使用Proguard时出现未知来源

时间:2015-05-04 16:26:37

标签: android proguard minify shrinkresources

如果我使用Proguard(minifyEnabled trueshrinkResources true)我的崩溃报告有点无用

这是Proguard的报告:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setVisibility(int)' on a null object reference
    at xx.xxxx.xxx.xxxxx.xxxxxx.restoreViewAfterLoading(Unknown Source)
    at xx.xxxx.xxx.xxxxx.xxxxxx.newInstance(Unknown Source)
                                                     onCreateView
                                                     onViewCreated
                                                     access$000
    at xx.xxxx.xxx.xxxxx.xxxxxx$1.success(Unknown Source)
    at xx.xxxx.xxx.xxxxx.xxxxxx$1.success(Unknown Source)
    at retrofit.CallbackRunnable$1.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

这是没有Proguard的正常报告:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setVisibility(int)' on a null object reference
    at xx.xxxx.xxx.xxxxx.xxxxxx.restoreViewAfterLoading(xxxxxx.java:123)
    at xx.xxxx.xxx.xxxxx.xxxxxx.access$000(xxxxxx.java:26)
    at xx.xxxx.xxx.xxxxx.xxxxxx$1.success(xxxxxx.java:96)
    at xx.xxxx.xxx.xxxxx.xxxxxx$1.success(xxxxxx.java:92)
    at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我能用Proguard来获取行号吗?

1 个答案:

答案 0 :(得分:9)

看起来你在名为restoreViewAfterLoading的方法中的某个文件中有一个NPE,其中在某个文件的第123行的ProgressBar(为空)上调用setVisibility。这一切都发生在改装回调上。因此,我首先想到的是在用户完成此活动/片段的情况下检查null。

要获得更好的行号,请将以下内容添加到您的proguard配置

# Preserve annotations, line numbers, and source file names
-keepattributes *Annotation*,SourceFile,LineNumberTable

这将保留模糊堆栈跟踪中的行号。

HTHS