设置minifyEnabled true
后,我在发布的应用程序中收到此错误
知道如何解决吗?
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)
gradle 文件中的设置:
release {
minifyEnabled true
shrinkResources true
zipAlignEnabled true
pseudoLocalesEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
在 ProGuard 配置文件中,您需要为缺少的方法添加-keep
规则rebase()
。以下-keep
选项可以解决问题;
-keep class android.content.res.Resources$Theme {
void rebase();
}
使用 ProGuard 操场,您可以在项目的类树中查看-keep
选项的效果。它可以帮助您创建微调的-keep
选项来解决类似问题。