How to debug with obfuscated (with ProGuard) applications on Android?
Asked Answered
S

5

73

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.

Sarmentum answered 12/10, 2010 at 9:46 Comment(0)
B
116

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.

Backswept answered 12/7, 2011 at 19:50 Comment(0)
T
15

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.

Teodoro answered 13/10, 2010 at 9:3 Comment(5)
This process is also explained at developer.android.com/guide/developing/tools/…Hamil
Coming in ADT 17 (currently a Preview release) are further changes to how PorGuard is configured for Android. tools.android.com/recent/proguardimprovements It doesn't change how to debug using the print mapping, but it will change how you configure ProGuard initially.Teodoro
@Teodoro i tried the same but out is the same as encoded value :( any help?Cardie
I don't understand how to use this. Can you please provide more information? Is it even possible to debug obfuscated apps?Leffler
this only works on my case in activities, but breakpoints in fragments are not hit. do you have any idea why it is happening?? RegardsEiten
J
8

To retrace back obfuscated ProGuard file do the following steps:

  1. You need to install Proguard.

  2. Proguard provides you with a UI mode which is great tool to retrace.

  3. Open up the proguardgui.sh which you find it in MAC machine

    /Users/{name}/Library/Android/sdk/tools/proguard/bin/proguardgui.sh
    

    You can run it through the terminal.

proguardgui

  1. You can then enter your mapping file and the snipped you want to retrace and it should be retraced

proguardgui outputs

Jeaninejeanlouis answered 21/5, 2020 at 11:29 Comment(0)
F
4

Paste your stack trace in stack_trace.txt

Run the following command: java -jar retrace.jar classes-processed.map stack_trace.txt

retrace.jar is at sdk\tools\proguard\lib\retrace.jar classes-processed.map is the output file generated by proguard when you did obfuscation

Firetrap answered 5/8, 2015 at 18:56 Comment(0)
P
1

Here's a link to official documentation on retrace tool from Android SDK: https://developer.android.com/studio/build/shrink-code#decode-stack-trace

This article is good too: https://medium.com/@maheshwar.ligade/de-obfuscate-stack-traces-6e19a52a3379

For all you copy-paste bros:

retrace.bat|retrace.sh [-verbose] mapping.txt [<stacktrace_file>]
Pointenoire answered 25/2, 2019 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.