Android ProGuard return Line Number

馋奶兔 提交于 2019-11-27 10:29:48

问题


Is there a way to get ProGuard to return a line number where the crash happened? I can use retrace to get to the method, but often for things like NullPointerException there are too many possibilities and in a large piece of code its extremely hard to determine the underlying cause as you have to check every object and it's life cycle to make sure nothing is wrong. It would really help if ProGuard could narrow this down to a line number for me.


回答1:


Add this line to your proguard-project.txt file.

# will keep line numbers and file name obfuscation
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

http://proguard.sourceforge.net/index.html#manual/usage.html




回答2:


When you create a new Android project, it tell you about which lines you might want to uncomment:

# 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

So, you should consider having these:

-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile

However, note that for some reason, Firebase Crashlytics team told me this line might interfere with their service:

-renamesourcefileattribute SourceFile

so you might not see good information of crashes stack trace if you use it.



来源:https://stackoverflow.com/questions/10158849/android-proguard-return-line-number

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