[英]java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityManagerCompat
[英]How to resolve " NoClassDefFoundError: Failed resolution of: Landroidx/core/animation/AnimatorCompatHelper;"
概括
我想将我的旧应用程序迁移到新的 Android Studio,更新构建工具并使用 AndroidX。
它甚至有点奏效。 该应用程序启动,甚至进入主屏幕......但不久后崩溃。
我试过的
我已经看过以下问题: NoClassDefFoundError android/support/v4/animation/AnimatorCompatHelper
java.lang.NoClassDefFoundError:解析失败: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/核心/动画/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)后,应用程序正确编译并运行,除了一些与迁移相关的问题外,正确运行。
检查您的 build.gradle(应用程序级别),查看是否缺少 androidx.core 库
如果缺少添加此依赖项
implementation 'androidx.core:core-ktx:1.2.0'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.