Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 974
mobileDev Avatar asked Sep 04 '16 23:09

mobileDev


People also ask

Does ProGuard obfuscate package name?

Obfuscating package names myapplication. MyMain is the main application class that is kept by the configuration. All other class names can be obfuscated. Note that not all levels of obfuscation of package names may be acceptable for all code.

What does ProGuard keep do?

-keep Specifies classes and class members (fields and methods) to be preserved as entry points to your code. For example, in order to keep an application, you can specify the main class along with its main method. In order to process a library, you should specify all publicly accessible elements.

Does ProGuard obfuscate XML?

ProGuard can't obfuscate strings. xml. You can use other software to obfuscate your file like DexGuard.


Video Answer


1 Answers

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.

like image 195
Tomik Avatar answered Oct 03 '22 20:10

Tomik