我把我的应用项目拆分成其他模块,在实现 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
文件中启用了Multidex,但仍然失败了。我像这样添加了Multidex:
implementation "androidx.multidex:multidex:2.0.0"
build.gradle
defaultConfig {
// Config stuff
multiDexEnabled = true
}
我希望将我的Application
类扩展为MultiDexApplication
类,并且进行调整,然而仍然失败了。
看起来我在这里缺少一个依赖项,但我找不到它。:c