android - java.lang.NoClassDefFoundError : Failed resolution of: Landroidx/arch/core/util/Cancellable 错误

标签 android androidx

我将我的应用程序项目拆分到其他模块中,在实现 DI 并将依赖项拆分到各个模块之后,我得到了这个异常:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/arch/core/util/Cancellable;
        at androidx.activity.ComponentActivity.<init>(ComponentActivity.java:69)
        at androidx.fragment.app.FragmentActivity.<init>(FragmentActivity.java:118)
        at androidx.appcompat.app.AppCompatActivity.<init>(AppCompatActivity.java:77)

然后,我检查了 ComponentActivity 类,是的,该类找不到 Cancellable 类。

package androidx.activity;  

import static android.os.Build.VERSION.SDK_INT;  

import android.os.Build;  
import android.os.Bundle;  
import android.view.View;  
import android.view.Window;  

import androidx.annotation.CallSuper;  
import androidx.annotation.ContentView;  
import androidx.annotation.LayoutRes;  
import androidx.annotation.NonNull;  
import androidx.annotation.Nullable;  
import androidx.arch.core.util.Cancellable; // <---- This class can't be found!
import androidx.lifecycle.GenericLifecycleObserver;  
import androidx.lifecycle.Lifecycle;  
import androidx.lifecycle.LifecycleOwner;  
import androidx.lifecycle.LifecycleRegistry;  
import androidx.lifecycle.ReportFragment;  
import androidx.lifecycle.ViewModelStore;  
import androidx.lifecycle.ViewModelStoreOwner;  
import androidx.savedstate.SavedStateRegistry;  
import androidx.savedstate.SavedStateRegistryController;  
import androidx.savedstate.SavedStateRegistryOwner;  

import java.util.WeakHashMap;  

/**  
 * Base class for activities that enables composition of higher level components. * <p>  
  * Rather than all functionality being built directly into this class, only the minimal set of  
 * lower level building blocks are included. Higher level components can then be used as needed * without enforcing a deep Activity class hierarchy or strong coupling between components. */public class ComponentActivity extends androidx.core.app.ComponentActivity implements  
  LifecycleOwner,  
  ViewModelStoreOwner,  
  SavedStateRegistryOwner {

看了包之后,我决定添加这个依赖:

实现“androidx.core:core:1.1.0-alpha05”

然而,它仍然失败。

然后我在 StackOverflow 中检查了一些建议使用 Multidex 的问题,因此,我在我的 build.gradle 文件中启用了 mutlidex,但它仍然失败

我这样添加了 Multidex:

实现“androidx.multidex:multidex:2.0.0”

构建.gradle

defaultConfig {  
// Config stuff
  multiDexEnabled = true  
}

并使我的 Application 类扩展 MultiDexApplication 类,但它仍然失败

似乎我在这里缺少一个依赖项,但我找不到它。 :c

最佳答案

根据 androidx.arch.core release notes :

The Cancellable interface has been deprecated due to a lack of composable infrastructure and its removal from public API in androidx.activity 1.0.0-alpha07. (aosp/945461)

因此您应该升级到 Activity 1.0.0-alpha07 或更高版本以移除 ComponentActivity 对 Cancellable 的依赖。当您升级到 Fragments 1.1.0-alpha07 或更高版本时,这会自动完成。

关于android - java.lang.NoClassDefFoundError : Failed resolution of: Landroidx/arch/core/util/Cancellable 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56279972/

相关文章:

java - 如何对 Android 平台的图像处理库进行单元测试?

java - Google Play 保存的游戏中 resolveConflict 的 snapshotId

android - launchFragmentInContainer 无法解析 Android 中的 Activity

android - ContentLoadingProgressBar 中的默认颜色更改

android - JaCoCo 显示 0% 的覆盖率,甚至所有测试都通过了

AndroidX 依赖项和 XML 导致崩溃

java - 如何在运行时获取设备高度和宽度?

java - 如何与 FragmentStatePagerAdapter 内的 Fragment 进行通信?

php - 将文件流式传输到 Android 客户端

java - 迁移到 AndroidX - ResultReceiver 在哪里