Deobfuscate production Android errors via uploading proguard rules mapping file to google play console
Asked Answered
C

4

5

Suddenly my released app crashed while opening just after installing the app from play-store. But problem is that when I am running the code in Android Studio in debug mode app does not crash.

When I looked for crash error on google play console I saw some obfuscated code not easy to guess from where error was coming.

java.lang.NullPointerException: 
  at com.wl.model.a.b (Unknown Source)
  at com.wl.model.a.a (Unknown Source)
  at com.wl.model.a$1.a (Unknown Source)
  at b.w$a.b (Unknown Source)
  at b.a.b.run (Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
  at java.lang.Thread.run (Thread.java:818)

From error I know there is some null pointer exception but could not trace its origin.

Google play console says upload de-obfuscation file to de-obfuscate the error code.

Now my problem is that I am not able to locate the de-obfuscation file in my project source folder.

I tried uploading the pro-guard rules file but google play console rejects it.

Please provide me the path or place where I can look for de-obfuscation file (where it is usually present).

Convertible answered 12/10, 2017 at 8:21 Comment(0)
B
6

After you assembled your release apk the file is here:

./gradlew clean assembleFLAVORRelease

app/build/outputs/mapping/FLAVOR/release/mapping.txt

Keep in mind, that you probably should check your proguard rules:

-keepattributes SourceFile,LineNumberTable

Without this attribute you won't see the line and source file name in the play console.

Baddie answered 12/10, 2017 at 8:47 Comment(1)
I will try this.Convertible
C
10

Some detailed answer and explanations to beginners like me -

Location of Mapping file to deobfuscate:

ProGuard saves the file in the app app/build/outputs/mapping/FLAVOR/release/mapping.txt.

or

/app/build/outputs/mapping/release/

Thanks to @chrjs for answering it.

Some Gotchas:

mapping.txt file gets overwritten every time you create a release build with ProGuard, so first take backup of that file before creating a new release. It will help to obfuscated stack trace from an older version of your app.

Apart from that there are two ways to obfuscate your code :

1. Upload your mapping.txt file to Google play Console:

When publishing your app on Google Play, you can upload the mapping.txt file for each version of your APK. Then Google Play will deobfuscate incoming stack traces from user-reported issues so you can review them in the Google Play Console.

2. Use local sdk tool retrace.sh/retrace.bat:

Some times you want to run the release version of your app(by changing build variant to release and running it) to cross check and fix the errors so that it does not happens in production ( when released to play-store).

To convert an obfuscated stack-trace to a readable one yourself, use the retrace script (retrace.bat on Windows; retrace.sh on Mac/Linux).

It is located in the <sdk-root>/tools/proguard/bin/ directory.

<sdk-root> is the place where your all android libraries and sdks were installed.

The script takes the mapping.txt file and your stack trace, producing a new, readable stack trace.

Command Syntax:

retrace.bat|retrace.sh [-verbose] mapping.txt [<stacktrace_file>]

For example:

retrace.bat -verbose mapping.txt obfuscated_trace.txt

I prefer local version of obfuscating as is quite handy to pre-check production errors.

Convertible answered 12/10, 2017 at 10:47 Comment(2)
This should be the accepted answer. Good summary! :)Baddie
@Baddie you pointed out in right direction in your answer. ThanksConvertible
B
6

After you assembled your release apk the file is here:

./gradlew clean assembleFLAVORRelease

app/build/outputs/mapping/FLAVOR/release/mapping.txt

Keep in mind, that you probably should check your proguard rules:

-keepattributes SourceFile,LineNumberTable

Without this attribute you won't see the line and source file name in the play console.

Baddie answered 12/10, 2017 at 8:47 Comment(1)
I will try this.Convertible
C
2

It's at build/outputs/proguard/release/mapping.txt
Make sure your ProGuard’s mapping.txt is from the same version of your compiled version. Mapping.txt gets replaced and changes every time you export your APK

Champlain answered 12/10, 2017 at 8:31 Comment(0)
E
0

To automatically include debug symbol, add to last line of app/build.gradle file:

android.buildTypes.release.ndk.debugSymbolLevel = 'FULL'
Euphoria answered 11/6, 2022 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.