使用Proguard

时间:2016-02-16 21:41:19

标签: android apk proguard android-proguard

我的应用程序在启用Proguard的情况下启动已签名的apk版本时崩溃。请注意,在常规调试模式下,应用程序不会崩溃。

FATAL EXCEPTION: AsyncTask #1
Process: orbyt.horizon, PID: 21671
       java.lang.RuntimeException: An error occurred while executing doInBackground()
           at android.os.AsyncTask$3.done(AsyncTask.java:309)
           at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
           at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
           at java.util.concurrent.FutureTask.run(FutureTask.java:242)
           at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
           at java.lang.Thread.run(Thread.java:818)
        Caused by: java.lang.NoSuchFieldError
           at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:688)
           at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:663)
           at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
           at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:171)
           at libcore.reflect.AnnotationAccess.getAnnotation(AnnotationAccess.java:72)
           at java.lang.Class.getAnnotation(Class.java:359)
           ... 
        Caused by: java.lang.NoSuchFieldException: No field LINK in class La/a/a/c/a/i; (declaration of 'a.a.a.c.a.i' appears in /data/app/orbyt.horizon-1/base.apk)
           at java.lang.Class.getDeclaredField(Native Method)
           at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:685)
           at 

现在,如果我猜测我会说Proguard混淆了一些不应该的类。那你怎么去调试呢?

这是我的proguard-rules.pro

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

# Retrofit 2.X
## https://square.github.io/retrofit/ ##

-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

# Butterknife

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

# Glide specific rules #
# https://github.com/bumptech/glide

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}


## Retrolambda specific rules ##

# as per official recommendation: https://github.com/evant/gradle-retrolambda#proguard
-dontwarn java.lang.invoke.*

# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**


#JodaTime
# These aren't necessary if including joda-convert, but
# most people aren't, so it's helpful to include it.
-dontwarn org.joda.convert.FromString
-dontwarn org.joda.convert.ToString

#twitter4j
-dontwarn twitter4j.**
-keep class twitter4j.** { *; }

#google
-dontwarn com.google.**

#okio
-dontwarn com.squareup.**
-dontwarn okio.**

#misc
-dontwarn com.google.code.**
-dontwarn oauth.signpost.**
-dontwarn twitter4j.**
-dontwarn javax.management.**
-dontwarn javax.xml.**
-dontwarn org.apache.**
-dontwarn org.slf4j.**
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
-optimizations !class/unboxing/enum
-keep  class com.fasterxml.jackson.annotation.** {*;}
-keep  class com.fasterxml.jackson.core.** {*;}
-keep  class com.fasterxml.jackson.databind.** {*;}
-keep class libcore.** { *; }

那么可能是什么导致了这个?

1 个答案:

答案 0 :(得分:0)

显然问题出在JRAW上,在我的proguard-rules.pro文件中添加以下行似乎解决了这个问题:

#jraw
-dontwarn net.dean.**
-keep class net.dean.** {*;}