5

I'm trying to figure out how to keep original line numbers with R8.

Doing an app with current AndroidStudio and obfuscating it with R8, and even uploading mapping.txt file to Google Play Console, the Stack Traces of the users are useless in some cases, because the lines of the crash are not the same as in the real non obfuscated file.

This is a sample, my class doesn't have 3000 lines, but the error is reported in line 3052 ( com.mypackage.activities.ManagerActivity.onCreate (ManagerActivity.java:3052) ):

Caused by: java.lang.NullPointerException: 
  at com.mypackage.activities.ManagerActivity.onCreate (ManagerActivity.java:3052)
  at android.app.Activity.performCreate (Activity.java:7136)
  at android.app.Activity.performCreate (Activity.java:7127)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1271)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2990)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3148)
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:78)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1861)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:193)
  at android.app.ActivityThread.main (ActivityThread.java:6819)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:497)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:912)

Is there a way to get the real line number of the error with R8 and AndroidStudio? Remember that this code is already deobfuscated with mapping.txt file

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • If the `mapping.txt` file is uploaded together with the APK, then the Google Play Console should run the deobfuscation automatically. Apparently that does not work in this case. If it is possible to get the original stacktrace from the user in the Google Play Console, then it is possible to run the deobfuscation locally instead, to try to figure what is wrong. For reference what version of Android Studio/AGP/R8 are you using? – sgjesse Oct 19 '20 at 10:16
  • Hi @sgjesse AS 4.0.1, AGP 4.0.1 and R8 i don't know, the default one coming in AS. Btw, i have some other stack traces reported and none of them display the real line numbers. And also in my other apps are the same, none of them displays the real line numbers. All my apps have the mapping file uploaded. What can i do to keep the real line numbers? I need to obfuscate the code but keeping the line numbers in stacktraces or at least something near to this. It's a very huge problem for me because i have a lot of stacktraces of that error, and can't solve it because of this issue with line numbers – NullPointerException Oct 26 '20 at 09:27
  • AGP 4.0.1 embeds R8 version 2.0.74. If the above is after deobfuscation/retracing, then there might be a problem with the mapping file. You can try to validate locally by using the [R8 retracing tool](https://developer.android.com/studio/command-line/retrace) with you mapping file and a stack trace from the app (you can force one locally by inserting a `throw new NullPointerException()`). If you can share the mapping file and maybe some stack traces with sgjesse@google.com and mkroghj@google.com we can try to help figuring out where this goes wrong. – sgjesse Oct 28 '20 at 16:25
  • thank you very much @sgjesse email sent – NullPointerException Oct 29 '20 at 19:25
  • @sgjesse please, can you add an answer telling that " -keepattributes LineNumberTable,SourceFile" solved the issue? I will accept it – NullPointerException Nov 12 '20 at 17:25
  • I have just filed a bug with exactly the same problem [here](https://stackoverflow.com/questions/64892774/google-play-console-incorrect-line-numbers-in-pre-launch-crash-report-using-map), but I already have `-keepattributes LineNumberTable,SourceFile`. I'm wondering if I have an issue elsewhere that's overriding this? and help much appreciated @sgjesse? – Simon Huckett Nov 18 '20 at 13:43

1 Answers1

5

In order for correct retracing of obfuscated stack traces it is required to have the following in the configuration file

 -keepattributes LineNumberTable,SourceFile

See https://developer.android.com/studio/build/shrink-code#decode-stack-trace for moe information.

sgjesse
  • 3,793
  • 14
  • 17