java.lang.NoSuchMethodException: android.content.res.Resources$Theme.rebase []

Viewed 1592

After I set minifyEnabled true, I got this error in my released app

Any idea how to solve it?

2020-07-01 11:51:33.651 30098-30098/? I/ResourcesCompat: Failed to retrieve rebase() method
    java.lang.NoSuchMethodException: android.content.res.Resources$Theme.rebase []
        at java.lang.Class.getMethod(Class.java:2069)
        at java.lang.Class.getDeclaredMethod(Class.java:2047)
        at androidx.core.content.res.ResourcesCompat$ThemeCompat$ImplApi23.rebase(SourceFile:3)
        at androidx.core.content.res.ResourcesCompat$ThemeCompat.rebase(SourceFile:3)
        at androidx.appcompat.app.AppCompatDelegateImpl.attachBaseContext2(SourceFile:32)
        at androidx.appcompat.app.AppCompatActivity.attachBaseContext(SourceFile:1)
        at com.kahkeshan.tv_app.base.BaseActivity.attachBaseContext(SourceFile:1)
        at android.app.Activity.attach(Activity.java:7244)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3080)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3282)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1970)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7156)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) 

settings in gradle file:

  release {
            minifyEnabled true
            shrinkResources true
            zipAlignEnabled true
            pseudoLocalesEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
1 Answers

In your ProGuard configuration file, you will need to add a -keep rule for the missing method rebase(). The following -keep option will do the trick;

-keep class android.content.res.Resources$Theme {
  void rebase();
}

Using the ProGuard Playground, you can see the effect of your -keep options in the class tree of your project. It can help you create fine-tuned -keep options to solve similar issues.

Related