Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProGuard return Line Number

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.

like image 879
Ali Avatar asked Apr 15 '12 01:04

Ali


2 Answers

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

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

https://www.guardsquare.com/en/products/proguard/manual/usage

like image 160
denizmveli Avatar answered Nov 16 '22 08:11

denizmveli


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.

like image 2
android developer Avatar answered Nov 16 '22 10:11

android developer