Proguard doesnt preserve the line numbers and method names in stacktrace

笑着哭i 提交于 2019-12-21 04:08:36

问题


Here are few lines from proguard-rules.pro

 -keepattributes *Annotation*
 -keepattributes Signature
 -keepattributes InnerClasses,EnclosingMethod
 -renamesourcefileattribute SourceFile
 -keepattributes SourceFile,LineNumberTable
 -keep public class * extends java.lang.Exception
 -dontwarn org.apache.http.**

Logcat output (error line number is listed as 1133, while my source file is 100 lines longer)

09-04 16:11:46.698 3827-5280/com.XX.main E/AndroidRuntime: FATAL EXCEPTION: IntentService[ActivityRecognizedTracker]
Process: com.XX.main, PID: 3827
java.lang.NullPointerException: Attempt to read from field 'double com.XX.trips.Trip.a' on a null object reference
at com.XX.ActivityRecognizedTracker.onHandleIntent(SourceFile:1133)

I am preserving the line numbers and source file attributes, but stack trace is still obfuscated. What am I doing wrong?


回答1:


AFAIK it's not possible to obfuscate the code and have original stacktraces. So if you want to see original method and class names in the stacktrace, you have to add -dontobfuscate rule.

But you don't really need the original stacktrace.

You are using -keepattributes SourceFile,LineNumberTable and that enables you to unambiguously retrace the stacktrace. Just don't forget to keep the generated mapping.txt file.

Moreover if you remove -renamesourcefileattribute SourceFile you'll see the original file names in the parentheses. The line number is already there, so you should be able to figure out without retracing where the exception actually happened.



来源:https://stackoverflow.com/questions/39322359/proguard-doesnt-preserve-the-line-numbers-and-method-names-in-stacktrace

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