41

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.

2 Answers 2

74

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

2
  • I can't find the proguard-project.txt file anywhere in my Android Studio solution. Where is it located?? Commented Feb 14, 2018 at 18:05
  • 1
    @MikeKeskinov, see proguardFiles getDefaultProguardFile, there you will find file names. If it doesn't exist, create one. Probably it's proguard-rules.pro.
    – CoolMind
    Commented Mar 5, 2018 at 9:00
1

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.

4
  • I was going to ask that, thank you so much for this info. DO you know if I do not use this line -renamesourcefileattribute SourceFile would that cause a problem? Thanks.
    – Hilal
    Commented Jan 4, 2021 at 19:42
  • 1
    @Hilal I decided not to use -renamesourcefileattribute SourceFile Commented Jan 5, 2021 at 20:05
  • "-renamesourcefileattribute SourceFile" will rename original file names. So if you got line number without its file name, you got nothing
    – Tony
    Commented Dec 6, 2022 at 12:39
  • So, it's good without it, right? Commented Dec 6, 2022 at 23:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.