Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 220
shiami Avatar asked Oct 12 '10 09:10

shiami


People also ask

How do you debug an obfuscated code?

To debug obfuscated JavaScript code, you need to use a JavaScript formatter or beautifier. Go to the following link to beautify JavaScript, In the left section, add your obfuscated JavaScript code and click Beautify as shown below, On clicking, you can see Beautified JavaScript code in the right section.

Does ProGuard affect debugging?

Building in debug mode does not invoke ProGuard, because it makes debugging more cumbersome.


1 Answers

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.

like image 180
Daniel Szmulewicz Avatar answered Sep 18 '22 17:09

Daniel Szmulewicz