Proguard不保留stacktrace中的行号和方法名称

mob*_*Dev 9 android proguard android-proguard

以下是来自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.**
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

我保留行号和源文件属性,但堆栈跟踪仍然是模糊的.我究竟做错了什么?

Tom*_*mik 15

AFAIK不可能混淆代码并拥有原始的堆栈跟踪.因此,如果要在stacktrace中查看原始方法和类名,则必须添加-dontobfuscate规则.

但你真的不需要原始的堆栈跟踪.

您正在使用-keepattributes SourceFile,LineNumberTable,这使您能够明确地回溯堆栈跟踪.只是不要忘记保留生成的mapping.txt文件.

此外,如果你删除,-renamesourcefileattribute SourceFile你会在括号中看到原始文件名.行号已经存在,所以你应该能够找到实际发生异常的地方.