java.lang.NoSuchMethodError in AndroidX in obfuscated app

Viewed 210

I've got a really weird error and I need an expert's eye to dig more into this issue.

In releasing my application in play store, I got some crashes in Crashlytics that seems to happen only on a few devices, right after a first installation of the application.

Fatal Exception: java.lang.NoSuchMethodError: No static method f(Landroid/content/Context;)Landroidx/core/app/n; in class Landroidx/core/app/n; or its super classes (declaration of 'androidx.core.app.n' appears in base.apk)
   at com.example.app.core.di.AppModule$Companion.provideNotificationManager(AppModule.kt:88)
   ...

The use of f and n shows that app is obfuscated with r8 and a proguard rule.

The source code where the crash is happening looks like this:

@Provides
    fun provideNotificationManager(context: Context): NotificationManagerCompat =
        NotificationManagerCompat.from(context)

NotificationManagerCompat.from(context) comes from androidx.core.app.NotificationManagerCompat. This class is obfuscated during build time.

We are using version 1.8.0 of androidx.core:core-ktx dependency.

Release note of this version does mention changes made on NotificationCompat.

Nothing about androidx has been added in proguard-rules.pro.

These lines are added in build.gradle

release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  • Why can we got a NoSuchMethodError exception whereas this method can be found when I decompile the apk?
  • Why can we got a NoSuchMethodError exception whereas error message says that "declaration of 'androidx.core.app.n' appears in base.apk"?
  • Why this error does not occurs on all devices (and they are many of them)?
  • Why this error is happening only after a first installation of the application (based on logs we got)?
  • Is this related to the fact that it concerns a static method ?
  • Do we need to add a rule in proguard file to keep all classes of androidx?

Thanks,

0 Answers
Related