简体   繁体   中英

How to resolve " NoClassDefFoundError: Failed resolution of: Landroidx/core/animation/AnimatorCompatHelper;"

Summary

I wanted to migrate an old app of mine into a new Android Studio, update the build tools and use AndroidX.

It even kinda worked. The app starts and even enters the main screen... but crashes shortly after.

What I have tried

I have already looked at the following questions: NoClassDefFoundError android/support/v4/animation/AnimatorCompatHelper

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityManagerCompat

The solution to the first was already present in my gradle file and that of the second doesn't really fit.

I believe the problem to be in the multidex configuration since I use the dexcount gradle plugin to count the numbers of methods in my apk and it has slightly more methods than can be contained in a single dex file. I looked into the relevant documentation: https://developer.android.com/studio/build/multidex Multidex was already enabled but I set the min SDK version to 21 and added a multidex-config.txt. The txt contains:

Landroidx/core/animation/AnimatorCompatHelper

This did nothing to fix the error, though.

I also checked the imported library 'FlexibleAdapter' for any updates. The Version I use still uses the old support libraries. I wanted to avoid updating the lib since the migration to the new version looks like a greater task. I would prefer doing the migration after the app is working again.

So this is a portion of my gradle file:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "funnyName"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexKeepProguard file('multidex-config.txt')
        }

        debug {
            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            multiDexKeepProguard file('multidex-config.txt')
        }
    }
    packagingOptions {
        exclude('META-INF/notice.txt')
        exclude('META-INF/NOTICE')
        exclude('META-INF/license.txt')
        exclude('META-INF/LICENSE')
        exclude('META-INF/LICENSE.txt')
        exclude('META-INF/NOTICE.txt')
        exclude 'META-INF/ASL2.0'
    }
    lintOptions {
        abortOnError false
    }

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    final BUTTERKNIFE_VERSION = '10.1.0'
    final ANDROID_PERMISSION_MANAGER_VERSION = '1.0.0'
    final DAGGER_VERSION = '2.5'
    final SUPPORT_LIBRARY_VERSION_LEGACY = '1.0.0'
    final HAMCREST_VERSION = '1.3'
    final MOCKITO_VERSION = '1.10.19'
    final ESPRESSO_VERSION = '3.1.0-alpha4'
    final UI_AUTOMATOR_VERSION = '2.1.2'
    final JUNIT_VERSION = '4.12'
    final RUNNER_VERSION = '1.1.0-alpha4'
    final ROBOLECTRIC_VERSION = '3.2.2'
    final MULTIDEX_VERSION = '2.0.0'
    final MOCKSERVER_VERSION = '3.5.0'
    final RETROFIT_VERSION = '2.5.0'
    final RXANDROID_VERSION = '2.0.1'
    final RXJAVA_VERSION = '2.0.4'
    def daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
    implementation "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
    annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
    implementation "com.github.buchandersenn:android-permission-manager:$ANDROID_PERMISSION_MANAGER_VERSION"
    implementation "androidx.legacy:legacy-support-core-utils:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "androidx.appcompat:appcompat:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "com.google.android.material:material:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "androidx.legacy:legacy-support-v13:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "androidx.legacy:legacy-support-v4:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "androidx.core:core:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "androidx.recyclerview:recyclerview:$SUPPORT_LIBRARY_VERSION_LEGACY"
    implementation "androidx.cardview:cardview:$SUPPORT_LIBRARY_VERSION_LEGACY"
    androidTestImplementation "androidx.appcompat:appcompat:$SUPPORT_LIBRARY_VERSION_LEGACY"

And this is a portion of the Stacktrace:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/animation/AnimatorCompatHelper;
        at eu.davidea.flexibleadapter.common.FlexibleItemAnimator.resetAnimation(FlexibleItemAnimator.java:646)
        at eu.davidea.flexibleadapter.common.FlexibleItemAnimator.animateMove(FlexibleItemAnimator.java:385)
        at androidx.recyclerview.widget.SimpleItemAnimator.animatePersistence(SimpleItemAnimator.java:138)
        at androidx.recyclerview.widget.RecyclerView$4.processPersistent(RecyclerView.java:632)
        at androidx.recyclerview.widget.ViewInfoStore.process(ViewInfoStore.java:237)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3994)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3652)
        at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1888)
        at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5044)

So is this a multidex configuration error or has this something to do with the outdated library? Or is it something else?

将 FlexibleAdapter 迁移到最新版本(使用 AndroidX)后,应用程序正确编译并运行,除了一些与迁移相关的问题外,正确运行。

Check your build.gradle (app level), see if androidx.core library is missing

if missing add this dependency

  implementation 'androidx.core:core-ktx:1.2.0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM