我正在尝试ColorMixer
在PreferenceActivity
. 这在部署到模拟器时以及在没有 proguard 的情况下导出时效果很好。但是当我在配置 proguard 的情况下导出它时,应用程序崩溃了。
我使用了最新的 Android SDK 附带的 proguard 配置。我添加了两行以至少可以看到代码“中断”的位置,并添加了两行以确保 proguard 使 CommonsWare 的内容保持不变。
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keep class com.commonsware.** { *; }
-keep interface com.commonsware.** { *; }
错误:
08-17 12:58:13.199: E/AndroidRuntime(922): FATAL EXCEPTION: main
08-17 12:58:13.199: E/AndroidRuntime(922): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class java.lang.reflect.Constructor
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.os.Looper.loop(Looper.java:137)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.reflect.Method.invoke(Method.java:511)
08-17 12:58:13.199: E/AndroidRuntime(922): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-17 12:58:13.199: E/AndroidRuntime(922): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-17 12:58:13.199: E/AndroidRuntime(922): at dalvik.system.NativeStart.main(Native Method)
08-17 12:58:13.199: E/AndroidRuntime(922): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class java.lang.reflect.Constructor
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.createItem(GenericInflater.java:397)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.inflate(GenericInflater.java:326)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.inflate(GenericInflater.java:263)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:269)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1411)
08-17 12:58:13.199: E/AndroidRuntime(922): at com.test.MainActivity.onCreate(SourceFile:14)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.Activity.performCreate(Activity.java:5008)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-17 12:58:13.199: E/AndroidRuntime(922): ... 11 more
08-17 12:58:13.199: E/AndroidRuntime(922): Caused by: java.lang.reflect.InvocationTargetException
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.reflect.Constructor.constructNative(Native Method)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-17 12:58:13.199: E/AndroidRuntime(922): at android.preference.GenericInflater.createItem(GenericInflater.java:383)
08-17 12:58:13.199: E/AndroidRuntime(922): ... 22 more
08-17 12:58:13.199: E/AndroidRuntime(922): Caused by: java.lang.RuntimeException: Exception finding R class
08-17 12:58:13.199: E/AndroidRuntime(922): at com.commonsware.cwac.parcel.ParcelHelper.<init>(SourceFile:37)
08-17 12:58:13.199: E/AndroidRuntime(922): at com.commonsware.cwac.colormixer.ColorPreference.<init>(SourceFile:39)
08-17 12:58:13.199: E/AndroidRuntime(922): ... 25 more
08-17 12:58:13.199: E/AndroidRuntime(922): Caused by: java.lang.ClassNotFoundException: com.test.R
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.Class.classForName(Native Method)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.Class.forName(Class.java:217)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.Class.forName(Class.java:172)
08-17 12:58:13.199: E/AndroidRuntime(922): at com.commonsware.cwac.parcel.ParcelHelper.<init>(SourceFile:34)
08-17 12:58:13.199: E/AndroidRuntime(922): ... 26 more
08-17 12:58:13.199: E/AndroidRuntime(922): Caused by: java.lang.NoClassDefFoundError: com/test/R
08-17 12:58:13.199: E/AndroidRuntime(922): ... 30 more
08-17 12:58:13.199: E/AndroidRuntime(922): Caused by: java.lang.ClassNotFoundException: com.test.R
08-17 12:58:13.199: E/AndroidRuntime(922): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-17 12:58:13.199: E/AndroidRuntime(922): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-17 12:58:13.199: E/AndroidRuntime(922): ... 30 more
首选项.xml:
<PreferenceCategory android:title="TitleCat" >
<com.commonsware.cwac.colormixer.ColorPreference
android:key="key"
android:summary="Summary2"
android:title="Title2" />
</PreferenceCategory>
ColorPreferenec.java 的第 39 行
ParcelHelper parcel=new ParcelHelper("cwac-colormixer", ctxt);
我将 CWAC-Parcel.jar 添加到 ColorMixer 项目,并将其添加到 Build Path。我根据需要在我的测试项目(包com.test
)的构建路径上添加了 ColorMixer 项目
有谁知道我应该更改什么设置才能让它与 proguard 一起使用,因为我认为它与 ColorMixer 或 Parcel 无关。(因为它表明 ColorPreference 正在从 R 包中“请求”数据)