问题
Android App was working with no crash, After updating the Gradle plugin to version 3.6 faced the runtime crash below:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.package.app, PID: 9420
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/R$drawable;
at androidx.appcompat.widget.AppCompatDrawableManager.<clinit>(AppCompatDrawableManager.java:113)
at androidx.appcompat.widget.AppCompatDrawableManager.get(Unknown Source:0)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at my.package.app.abstracts.BaseActivity.onCreate(BaseActivity.java:94)
at my.package.app.ui.activity_splash.SplashActivity.onCreate(SplashActivity.java:48)
at android.app.Activity.performCreate(Activity.java:7335)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
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)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.R$drawable" on path: DexPathList[[zip file "/data/app/my.package.app-ubNE5Y0S9Ec7hNJGohi9Sw==/base.apk"],nativeLibraryDirectories=[/data/app/my.package.app-ubNE5Y0S9Ec7hNJGohi9Sw==/lib/arm, /data/app/my.package.app-ubNE5Y0S9Ec7hNJGohi9Sw==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at androidx.appcompat.widget.AppCompatDrawableManager.<clinit>(AppCompatDrawableManager.java:113)
at androidx.appcompat.widget.AppCompatDrawableManager.get(Unknown Source:0)
at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at my.package.app.abstracts.BaseActivity.onCreate(BaseActivity.java:94)
at my.package.app.ui.activity_splash.SplashActivity.onCreate(SplashActivity.java:48)
at android.app.Activity.performCreate(Activity.java:7335)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3119)
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)
ext.gradlVersion = '3.6.0'
...
classpath "com.android.tools.build:gradle:$gradlVersion"
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
回答1:
First implement multidex
into your project then restart android studio
and run your app still you face issue then after you nee to downgrade your android studio's
stable version 3.5.3
Below Android Studio 3.5
disable Instant run:
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
Issue: Click Me , Click Me
Hope this mey help you
回答2:
First Take a backup of your project after Migrate your project in AndroidX
- Goto Toolbar into Refactor
- Goto bottom option and select to Migrate to androidX
And migrate it. Check if the error still happens.
来源:https://stackoverflow.com/questions/60423895/android-app-runtime-crash-after-update-gradle-plugin-3-6