【问题标题】:Why do I get a Theming error just after using Proguard?为什么我在使用 Proguard 后会出现主题错误?
【发布时间】:2015-09-25 22:33:30
【问题描述】:

我之前没用过proguard,现在因为三星的臭虫而强制使用它:https://code.google.com/p/android/issues/detail?id=78377

所以,基本上,我遵循了所有的解释,并在我的 gradle 文件中添加了这个:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }
}

我的文件包含我需要解决上述错误的行:

-keep class !android.support.v7.internal.view.menu.**,** {*;}

注意:我关注了很多很多的proguard模板文件,在那里尝试了很多代码,所以不知道该怎么做。

该应用程序在我的手机上调试时编译得很好,但是一旦我尝试编译 apk 并上传它,我就收到了这个错误:

IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

请不要将我指向 style.xml,主题是 Appcompat,它在调试时工作正常。

非常感谢任何帮助或提示。

【问题讨论】:

    标签: android themes proguard


    【解决方案1】:

    我终于用上了这个文件:https://stackoverflow.com/a/8181232/327402

    现在工作正常。

    ##---------------Begin: proguard configuration common for all Android apps ----------
    -optimizationpasses 5
    -dontusemixedcaseclassnames
    -dontskipnonpubliclibraryclasses
    -dontskipnonpubliclibraryclassmembers
    -dontpreverify
    -verbose
    -dump class_files.txt 
    -printseeds seeds.txt 
    -printusage unused.txt 
    -printmapping mapping.txt 
    -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
    
    
    -allowaccessmodification
    -keepattributes *Annotation*
    -renamesourcefileattribute SourceFile
    -keepattributes SourceFile,LineNumberTable
    -repackageclasses ''
    
    
    -keep public class * extends android.app.Activity
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Service
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider
    -keep public class * extends android.app.backup.BackupAgentHelper
    -keep public class * extends android.preference.Preference
    -keep public class com.android.vending.licensing.ILicensingService
    -dontnote com.android.vending.licensing.ILicensingService
    
    
    # Explicitly preserve all serialization members. The Serializable interface
    # is only a marker interface, so it wouldn't save them.
    -keepclassmembers class * implements java.io.Serializable {
        static final long serialVersionUID;
        private static final java.io.ObjectStreamField[] serialPersistentFields;
        private void writeObject(java.io.ObjectOutputStream);
        private void readObject(java.io.ObjectInputStream);
        java.lang.Object writeReplace();
        java.lang.Object readResolve();
    }
    
    
    # Preserve all native method names and the names of their classes.
    -keepclasseswithmembernames class * {
        native <methods>;
    }
    
    
    -keepclasseswithmembernames class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    
    
    -keepclasseswithmembernames class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    
    
    # Preserve static fields of inner classes of R classes that might be accessed
    # through introspection.
    -keepclassmembers class **.R$* {
      public static <fields>;
    }
    
    
    # Preserve the special static methods that are required in all enumeration classes.
    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    
    -keep public class * {
        public protected *;
    }
    
    
    -keep class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator *;
    }
    ##---------------End: proguard configuration common for all Android apps ----------
    
    
    ##---------------Begin: proguard configuration for Gson  ----------
    # Gson uses generic type information stored in a class file when working with fields. Proguard
    # removes such information by default, so configure it to keep all of it.
    -keepattributes Signature
    
    
    # Gson specific classes
    -keep class sun.misc.Unsafe { *; }
    #-keep class com.google.gson.stream.** { *; }
    
    
    # Application classes that will be serialized/deserialized over Gson
    -keep class com.google.gson.examples.android.model.** { *; }
    
    
    ##---------------End: proguard configuration for Gson  ----------
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-11
      • 1970-01-01
      • 2011-12-23
      • 2012-06-05
      • 1970-01-01
      • 2018-01-07
      • 2017-09-05
      相关资源
      最近更新 更多