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

十年热恋 提交于 2020-12-26 11:06:27

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/64385769/how-to-keep-original-line-numbers-in-stack-traces-with-r8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!