【发布时间】:2012-04-26 21:08:58
【问题描述】:
有没有办法让 ProGuard 返回发生崩溃的行号?
我可以使用retrace 来获取该方法,但通常对于NullPointerException 之类的事情有太多的可能性,并且在大量代码中很难确定根本原因,因为您必须检查每个对象并且它的生命循环以确保没有任何问题。如果 ProGuard 可以将其缩小到对我来说是一个行号,那真的很有帮助。
【问题讨论】:
有没有办法让 ProGuard 返回发生崩溃的行号?
我可以使用retrace 来获取该方法,但通常对于NullPointerException 之类的事情有太多的可能性,并且在大量代码中很难确定根本原因,因为您必须检查每个对象并且它的生命循环以确保没有任何问题。如果 ProGuard 可以将其缩小到对我来说是一个行号,那真的很有帮助。
【问题讨论】:
将此行添加到您的 proguard-project.txt 文件中。
# will keep line numbers and file name obfuscation
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
https://www.guardsquare.com/en/products/proguard/manual/usage
【讨论】:
proguardFiles getDefaultProguardFile,在那里你会找到文件名。如果不存在,则创建一个。可能是proguard-rules.pro。
当您创建一个新的 Android 项目时,它会告诉您哪些行可能需要取消注释:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
所以,你应该考虑拥有这些:
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
但是,请注意,由于某种原因,Firebase Crashlytics 团队告诉我这条线路可能会干扰他们的服务:
-renamesourcefileattribute SourceFile
因此,如果您使用它,您可能看不到有关崩溃堆栈跟踪的良好信息。
【讨论】:
-renamesourcefileattribute SourceFile 会导致问题吗?谢谢。
-renamesourcefileattribute SourceFile