Throwable().getStackTrace()[0].getLineNumber() obfuscated by proguard Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Throwable().getStackTrace()[0].getLineNumber() obfuscated by proguard without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Before Proguard with:

Throwable().getStackTrace()[0].getLineNumber();

I got:

482

After Proguard I got:

41

Which is obviously wrong.

Here is the tested rules to solve this problem :

-keep class java.lang.StackElement
-keepattributes StackTraceElement
-keepattributes SourceFile,LineNumberTable
-keepattributes Signature
-keepattributes InnerClasses,EnclosingMethod
-keepattributes getStackTrace

But it doesn’t work. Is there any specific rules to let this piece of code work properly ?

Answer

According to the manual, you need to do this:

-renamesourcefileattribute SourceFile    
-keepattributes SourceFile,LineNumberTable

and you need to use -printmapping to save the mappings so that you can then decode the obfuscated stacktraces.

I should point out that references to classes and methods in the standard class library will always be retained since they are needed when your code is loaded. Therefore this “-keep” is superfluous:

-keep class java.lang.StackElement

And you are also telling Proguard to keep attributes called “StackTraceElement” and “getStackTrace” which don’t exist. The list of supported attributes is documented here

See also:

We are here to answer your question about Throwable().getStackTrace()[0].getLineNumber() obfuscated by proguard - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji