Search code examples
androidproguardandroid-proguard

Proguard doesnt preserve the line numbers and method names in stacktrace


Here are few lines from 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 output (error line number is listed as 1133, while my source file is 100 lines longer)

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)

I am preserving the line numbers and source file attributes, but stack trace is still obfuscated. What am I doing wrong?


Solution

  • AFAIK it's not possible to obfuscate the code and have original stacktraces. So if you want to see original method and class names in the stacktrace, you have to add -dontobfuscate rule.

    But you don't really need the original stacktrace.

    You are using -keepattributes SourceFile,LineNumberTable and that enables you to unambiguously retrace the stacktrace. Just don't forget to keep the generated mapping.txt file.

    Moreover if you remove -renamesourcefileattribute SourceFile you'll see the original file names in the parentheses. The line number is already there, so you should be able to figure out without retracing where the exception actually happened.