Wrong line number google play crash report

Viewed 466

I have google play crash like this

java.lang.NullPointerException: 
  at java.util.Objects.requireNonNull (Objects.java:109)
  at f0.k.e.b.b.a.<init> (SourceFile:1)
  at com.activities.galleryscan.ScanBarcodeFromFileActivity$b.g (SourceFile:28)
  at h0.r.o.a.a.d (SourceFile:3)

Here the line number SourceFile:28 not correct why?

I was uploaded the App Bundle signed with proguard.

According to This no need to upload mapping file to console in App Bundle

even then line number not correct why?

And I also

add this

-keepattributes SourceFile,LineNumberTable

-renamesourcefileattribute SourceFile

lines in proguard-rules.pro

even then line number not correct why?

3 Answers

I was getting correct line numbers for Debug and incorrect ones for Release.

If your build config specified with debuggable=false then R8 generates incorrect line numbers.

To make it work correctly set debuggable=true Eg

buildTypes {
    debug {
        debuggable true
        minifyEnabled true
        proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.debug
    }
    release {
        debuggable true
        minifyEnabled true
        proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.release
    }
}

This solution Work for me

if you have multiple proguard-rules.pro files of modules then add

this lines in every proguard-rules.pro files

-keepattributes SourceFile,LineNumberTable

-renamesourcefileattribute SourceFile

As per Android documentation,

After R8 obfuscates your code, understanding a stack trace is difficult (if not impossible) because names of classes and methods might have been changed. Besides renaming, R8 can also change the line numbers present in the stack traces to achieve additional size savings when writing the DEX files. Fortunately, R8 creates a mapping.txt file each time it runs, which contains the obfuscated class, method, and field names mapped to the original names. This mapping file also contains information to map the line numbers back to the original source file line numbers. R8 saves the file in the <module-name>/build/outputs/mapping/<build-type>/ directory.

So you need to find the mapping.txt file and upload it in google play console every time a new build is pushed.

You can find more information about the same here on android developer guide.

Related