In the process of optimizing an Android application, R8 and Proguard obfuscate the names of packages, classes and methods; this makes applications smaller and faster to run but can also be used partly in order to make the application more difficult to understand to someone using decompilation tools.

This obfuscation is beneficial in most cases, but can make it difficult to understand a stacktrace appearing in a crash. Fortunately we can revert it in order to analyze it properly, using a "mapping file" that is generated during the build process.

Use the following steps in order to deobfuscate a stacktrace:

Option 1: Using Anrdoid Studio 

Use the menu Analyze > Analyze Stack Trace or Thread Dump. Copy & paste the stacktrace there.

Option 2: Using the ProGuard GUI tool

  • Locate and launch the application in <android-sdk>/tools/proguard/lib/proguardgui.jar 
  • Select the “ReTrace” option on the left column.
  • Select your mapping file. You can find it in the following path on your build: <project>/<module>/build/outputs/mapping/<release>  or <debug>/mapping.txt 
  • Copy & paste your obfuscated stack trace from Bugfender the tool in the "Obfuscated stack trace" box.
  • Click ‘Retrace’ button.

Option 3: Command line Method

  • Copy & paste your obfuscated stack trace from Bugfender to a text file (ex: stacktrace.txt ).
  • Locate the the retrace tool in the Android SDK directory, it will be in <android-sdk>/tools/proguard/bin/ or in Windows it will be <android-sdk>\tools\proguard\bin\retrace.bat .
  • Run the tool with the mapping.txt file and the stacktrace file: mapping.txt stacktrace.txt 
  • The command will output the de-obfuscated stacktrace.

Where is my Android SDK?

The tools you will need are located in the Android SDK folder. By default it is located in the following paths:

  • In Windows: C:\Program Files (x86)\Android\android-sdk 
  • In macOS: ~/Library/Android/sdk on MacOS 
  • In Linux: ~/Android/sdk   

Even if the retrace tool is very powerful, depending on the degree of optimization performed it might not be possible to reconstruct the original stacktrace, even with the mapping file.

The following parameters are recommended in your proguard.cfg  file:

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
Did this answer your question?