繁体   English   中英

Android Holoeverywhere Proguard地狱

[英]Android Holoeverywhere Proguard hell

使用proguard模糊处理在发布模式下测试我的应用程序时出现以下错误:

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

我的proguard.txt文件:

-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

如果我禁用混淆,应用程序运行正常。 你能告诉我发生了什么吗?

错误发生在Holoeverywhere的SystemServiceManager.java中。 如果您阅读了代码,您会注意到它是故意抛出错误,因为注释出了问题

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);
}

检查proguard故障排除文档显示默认情况下除非添加此注释,否则将删除注释

-keepattributes *Annotation*

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM