How to keep original line numbers in stack traces with R8?
Asked Answered
K

1

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

Kenti answered 16/10, 2020 at 8:42 Comment(6)
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?Wadai
Hi @Wadai 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 numbersKenti
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 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 [email protected] and [email protected] we can try to help figuring out where this goes wrong.Wadai
thank you very much @Wadai email sentKenti
@Wadai please, can you add an answer telling that " -keepattributes LineNumberTable,SourceFile" solved the issue? I will accept itKenti
I have just filed a bug with exactly the same problem here, 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?Unionist
W
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.

Wadai answered 20/11, 2020 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.