How to debug with obfuscated (with ProGuard) applications on Android?
When I got something like this
ERROR/AndroidRuntime(18677): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(18677): at com.companyname.a.a.a(Unknown Source)
How can I know where the problem is and debug this issue? I only got the mapping output from ProGuard and don't know the line number. Thanks.
Add the following lines to your proguard configuration.
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
Now your stack traces will include line numbers, and by using the retrace tool that ships with proguard (included in the Android SDK), you are able to debug like normal.
Note that even if you didn't use these two configuration options, retrace still can output useful information provided you have the mappings file, albeit not totally unambiguously.
Note: the file with the mappings is produced by the proguard configuration option:
-printmapping outputfile.txt
In the ant file shipped with the Android SDK, it is set to mapping.txt.
Good luck.
To make use of any stack traces from your Android Market account, you can use your map file, produced with the-printmapping
option in the ProGuard config, with ReTrace (ProGuard companion tool) to decode the stack trace. You can also decode by hand using the contents of the map file, but this is tedious.
In the ProGuard Manual under examples, there is a section about producing useful obfuscated stack traces including how to keep line numbers.
Unfortunately if you did not set the ProGuard to keep the line numbers, then you will only be able to identify the method that throws the exception.