簡體   English   中英

java.lang.NoClassDefFoundError:無法解決以下問題:Landroidx / arch / core / util / Cancellable

[英]java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/arch/core/util/Cancellable

我將我的應用程序項目拆分為其他模塊,並在實現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

根據androidx.arch.core發行說明

由於缺少可組合的基礎結構,並且已從androidx.activity 1.0.0-alpha07公共API中刪除了該接口,因此不推薦使用Cancellable接口。 aosp / 945461

因此,您應該升級到Activity 1.0.0-alpha07或更高版本,以刪除ComponentActivity對Cancellable的依賴。 當您升級到Fragments 1.1.0-alpha07或更高版本時,將自動完成此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM