java - 如何解决 "NoClassDefFoundError: Failed resolution of: Landroidx/core/animation/AnimatorCompatHelper;"

标签 java android android-gradle-plugin

总结

我想将我的旧应用迁移到新的 Android Studio,更新构建工具并使用 AndroidX。

它甚至有点管用。该应用程序启动甚至进入主屏幕...但不久后就崩溃了。

我尝试过的

我已经看过以下问题: NoClassDefFoundError android/support/v4/animation/AnimatorCompatHelper

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

第一个的解决方案已经存在于我的 gradle 文件中,而第二个的解决方案并不适合。

我认为问题出在 multidex 配置中,因为我使用 dexcount gradle 插件来计算我的 apk 中的方法数量,并且它的方法比单个 dex 文件中包含的方法略多。我查看了相关文档:https://developer.android.com/studio/build/multidex Multidex 已启用,但我将最低 SDK 版本设置为 21 并添加了 multidex-config.txt。 txt 包含:

Landroidx/core/animation/AnimatorCompatHelper

不过,这并没有解决错误。

我还检查了导入的库“FlexibleAdapter”是否有任何更新。我使用的版本仍然使用旧的支持库。我想避免更新库,因为迁移到新版本看起来是一项更大的任务。我更愿意在应用程序再次运行后进行迁移。

所以这是我的 gradle 文件的一部分:

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"

这是 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)

这是 multidex 配置错误还是与过时的库有关?还是其他原因?

最佳答案

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

关于java - 如何解决 "NoClassDefFoundError: Failed resolution of: Landroidx/core/animation/AnimatorCompatHelper;",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55462262/

相关文章:

java - 如何使用 JPA 和 @Query 命名参数将数据导入 MySQL

java - 如何在 java 中为 ArrayList 中的数据指定排序顺序?

android - 通过私有(private)地址访问网站

android - 从 kml 获取地标的坐标

android - 组织.gradle.api.tasks.TaskExecutionException : Execution failed for task ':mergeDevOnlySlDebugResources' only on Jenkins

java - 属性 'userDetailsService' : no matching editors or conversion strategy found

android - 为 Android 开发时,如何在 AsyncTask 中使用 Eclipse 调试器?

android studio : Error : Module version com. android.support :support-v13:13. 0.0 依赖库但本身不是库

android - 我想创建我的自定义 'build.gradle'文件

java - 驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;