Proguard 不保留堆栈跟踪中的行号和方法名称

Proguard doesnt preserve the line numbers and method names in stacktrace

以下是 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输出(错误行号列为1133,而我的源文件长了100行)

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)

我保留了行号和源文件属性,但堆栈跟踪仍然模糊不清。我做错了什么?

据我所知,不可能混淆代码并拥有原始堆栈跟踪。所以如果你想在堆栈跟踪中看到原始方法和 class 名称,你必须添加 -dontobfuscate 规则。

但您并不真的需要原始堆栈跟踪。

您正在使用 -keepattributes SourceFile,LineNumberTable,这使您能够 unambiguously retrace the stacktrace。只是不要忘记保留生成的 mapping.txt 文件。

此外,如果您删除 -renamesourcefileattribute SourceFile,您会在括号中看到原始文件名。行号已经存在,因此您应该能够在不回溯异常实际发生的位置的情况下弄清楚。