java.lang.NoClassDefFoundError:无法解决以下问题:Landroidx / arch / core / util / Cancellable

时间:2019-05-23 17:04:04

标签: 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 {

看完软件包后,我决定添加此依赖项:

implementation "androidx.core:core:1.1.0-alpha05"

但是,它仍然失败。

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

我这样添加了Multidex:

implementation "androidx.multidex:multidex:2.0.0"

build.gradle

defaultConfig {  
// Config stuff
  multiDexEnabled = true  
}

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

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

1 个答案:

答案 0 :(得分:1)

按照androidx.arch.core release notes

  

Cancellable接口已被弃用,原因是缺少可组合的基础结构,并且已从androidx.activity 1.0.0-alpha07中的公共API中删除了该接口。 (aosp/945461

因此,您应该升级到活动1.0.0-alpha07或更高版本,以删除ComponentActivity对Cancellable的依赖。升级到Fragments 1.1.0-alpha07或更高版本时,将自动完成此操作。