Home » Android » Android Crashlytics sending incorrect line number

Android Crashlytics sending incorrect line number

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m trying to integrate Crashlytics with my app and it’s working, however the line number passed through seems to be incorrect. This is a stack I’m getting for my test exception:

Fatal Exception: java.lang.RuntimeException: This is a test crash
   at com.myapp.testapp.activity.MainActivity.animateReveal(MainActivity.java:42453)
   at com.myapp.testapp.activity.MainActivity.onClick(MainActivity.java:1356)
   at android.view.View.performClick(View.java:5204)
   at android.view.View$PerformClick.run(View.java:21153)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5417)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

So my crash is on line number 1453 but for some reason it’s showing up as 42453? Interestingly, the next line number in the stack is correct…

Proguard:

# Crashlitics

-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keepattributes *Annotation*
How to&Answers:

Did you try this?

For Fabric to properly de-obfuscate your crash reports, you need to
remove this line from your configuration file, or we won’t be able to automatically upload your mapping file:

-printmapping mapping.txt

and

-keep class com.crashlytics.** { *; }

-dontwarn com.crashlytics.**

Answer:

Likely it’s because you’re using a release build which will remove comments/ white spaces.

If you’re using a debug build then it may show the correct lines, because it won’t optimize your source code…

Still I’m guessing there is another reason for the line numbers to show incorrect, because Fabric was telling me the crash was happening at line 400, even though that function was called at line 300. I mean if comments and white spaces are to be removed, Fabric should have told line some line less than 300, not more!

Answer:

In my case switching from ‘proguard-android-optimize.txt’ default proguard file to ‘proguard-android.txt’ fixed the issue. Using the optimized version of the proguard file can introduce certain risks and it seems that this is one of them.

Answer:

android.enableR8.libraries = false

android.enableR8 = false