0

I'm trying to use the ColorMixer of CommonsWare in a PreferenceActivity. This works fine when deploying to the emulator and when I export without proguard. But when I export it with proguard configured, the application crashes.

I used the proguard configuration which comes with the latest Android SDK. I add two lines to be able to see at least where the code "breaks", and two to make sure proguard leaves the CommonsWare stuff untouched.

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keep class com.commonsware.** { *; }
-keep interface com.commonsware.** { *; }

The error:

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

pref.xml:

<PreferenceCategory android:title="TitleCat" >
    <com.commonsware.cwac.colormixer.ColorPreference
        android:key="key"
        android:summary="Summary2"
        android:title="Title2" />
</PreferenceCategory>

Line 39 of ColorPreferenec.java

ParcelHelper parcel=new ParcelHelper("cwac-colormixer", ctxt);

I added the CWAC-Parcel.jar to the ColorMixer project, and added it to the Build Path. I added the ColorMixer project as required on the build path in my Test project (package com.test)

Does anyone have an idea what setting I should change to have it working with proguard, as I don't think it's related to ColorMixer or Parcel. (as it indicated that the ColorPreference is "requesting" data from the R package)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Tom
  • 2,242
  • 18
  • 27

0 Answers0