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

16

这里是来自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)

我保留了行号和源文件属性,但堆栈跟踪仍然被混淆了。我做错了什么?

1个回答

22

据我所知,无法混淆代码并保留原始的堆栈跟踪信息。因此,如果您想在堆栈跟踪中看到原始方法和类名称,则需要添加-dontobfuscate规则。

但实际上您并不需要原始的堆栈跟踪信息。

您正在使用-keepattributes SourceFile,LineNumberTable,这使您可以清晰地重新跟踪堆栈跟踪信息。只需不要忘记保留生成的mapping.txt文件。

此外,如果您删除-renamesourcefileattribute SourceFile,您将在括号中看到原始文件名。行号已经在那里,因此您应该能够在不重新跟踪的情况下确定异常实际发生的位置。


谢谢!你帮我解决了我需要的问题。 - David Vávra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接