Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I split my app project into other modules and after implementing DI and splitting the dependencies across the modules, I get this exception:

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)

Then, I check the ComponentActivity class and, yes, said class can´t find the Cancellableclass.

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 {

After taking a look at the package, I decided to add this dependency:

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

yet, it still fails.

Then I checked some questions here in StackOverflow that recommended use Multidex, so, I enabled mutlidex in my build.gradlefile but yet, it still fails

I added Multidex like this:

implementation "androidx.multidex:multidex:2.0.0"

build.gradle

defaultConfig {  
// Config stuff
  multiDexEnabled = true  
}

and making my Application class extend the MultiDexApplication class, yet, it still fails

Seems like im missing a dependency here, but I can't find it. :c

like image 365
Alfredo Bejarano Avatar asked May 23 '19 17:05

Alfredo Bejarano


1 Answers

As per the 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)

Therefore you should upgrade to Activity 1.0.0-alpha07 or higher to remove ComponentActivity's dependency on Cancellable. This is automatically done when you upgrade to Fragments 1.1.0-alpha07 or higher.

like image 83
ianhanniballake Avatar answered Nov 04 '22 06:11

ianhanniballake