Question

I am getting the following error while testing my app in release mode, with proguard obfuscation:

08-09 21:44:06.140: E/AndroidRuntime(4465): FATAL EXCEPTION: main
08-09 21:44:06.140: E/AndroidRuntime(4465): java.lang.ExceptionInInitializerError
08-09 21:44:06.140: E/AndroidRuntime(4465):     at java.lang.Class.newInstanceImpl(Native Method)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at java.lang.Class.newInstance(Class.java:1409)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.Instrumentation.newApplication(Instrumentation.java:957)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.Instrumentation.newApplication(Instrumentation.java:942)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.LoadedApk.makeApplication(LoadedApk.java:461)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3264)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.ActivityThread.access$2200(ActivityThread.java:117)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.os.Looper.loop(Looper.java:123)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at android.app.ActivityThread.main(ActivityThread.java:3687)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at java.lang.reflect.Method.invokeNative(Native Method)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at java.lang.reflect.Method.invoke(Method.java:507)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at dalvik.system.NativeStart.main(Native Method)
08-09 21:44:06.140: E/AndroidRuntime(4465): Caused by: java.lang.RuntimeException: SystemServiceCreator must be implement SystemService
08-09 21:44:06.140: E/AndroidRuntime(4465):     at org.holoeverywhere.SystemServiceManager.register(Unknown Source)
08-09 21:44:06.140: E/AndroidRuntime(4465):     at org.holoeverywhere.app.Application.<clinit>(Unknown Source)
08-09 21:44:06.140: E/AndroidRuntime(4465):     ... 16 more

My proguard.txt file:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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

-keepclasseswithmembernames class * {
   native <methods>;
}

-keepclasseswithmembers class * {
   public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
   public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
  public void *(android.view.View);
}

-keepclassmembers enum * {
   public static **[] values();
   public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
 public static final android.os.Parcelable$Creator *;
}

-keepattributes Signature 

-keep class sun.misc.Unsafe { *; }

-keep class org.springframework.** { *; }
-keep class org.codehaus.jackson.** { *; }
-keep class org.holoeverywhere.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep class com.facebook.** { *; }

-dontwarn org.springframework.**
-dontwarn org.apache.**

-libraryjars libs/commons-collections-3.2.1.jar
-libraryjars libs/congregando-message-1.0.0-SNAPSHOT.jar
-libraryjars libs/gson-2.2.3.jar
-libraryjars libs/spring-android-auth-1.0.1.RELEASE.jar
-libraryjars libs/spring-android-core-1.0.1.RELEASE.jar
-libraryjars libs/spring-android-rest-template-1.0.1.RELEASE.jar

If i disable the obfuscation, the application runs fine. Could you tell me what is going on?

Was it helpful?

Solution

The error is in SystemServiceManager.java of Holoeverywhere. If you read the code you'll noticed that it is intentionally throwing the error as something is going wrong with annotations

public static void register(Class<? extends SystemServiceCreator<?>> clazz) {
    if (!clazz.isAnnotationPresent(SystemService.class)) {
        throw new RuntimeException(
                "SystemServiceCreator must be implement SystemService");
    }
    SystemService systemService = clazz.getAnnotation(SystemService.class);
    final String name = systemService.value();
    if (name == null || name.length() == 0) {
        throw new RuntimeException("SystemService has incorrect name");
    }
    MAP.put(name, clazz);
}

A check of the proguard troubleshooting document shows that by default it removes annotations unless you add this

-keepattributes *Annotation*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top