Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown Source when I use Proguard

My crash report is a little bit useless if I use Proguard (minifyEnabled true and shrinkResources true)

This is the report with 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)

And this is the normal report without 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)

Is there something I can do to get line numbers with Proguard?

like image 590
Ralph Bergmann Avatar asked May 04 '15 16:05

Ralph Bergmann


1 Answers

Looks like you have a NPE in some file in the method called restoreViewAfterLoading where setVisibility is called on a ProgressBar (which is null) around line 123 of some file. This all happens on a retrofit callback. So my first thoughts to fix is to check for null in case the user has finished this activity/fragment.

to get better line numbering, Add the following to your proguard configuration

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

This will preserve line numbers in obfuscated stack traces.

HTHs

like image 182
petey Avatar answered Dec 01 '22 22:12

petey