Josip Domazet
Josip Domazet

Reputation: 2890

How to fix "Unable to load class 'dagger.Multibindings'" due to problems with gradle

I am currently developing an android application (Min. API-Level 21) with Android Studio 3.4.2. When I tried to sync my gradle (I was adding dagger dependencies) I seem to have lost my internet connection, therefore resulting in an corrupted gradle.

So far I've tried deleting gradle and IDE caches, deleting and redownloading my entire gradle, restarting the IDE, using a local gradle, restarting my PC and reimporting the project...

I virtually tried every single answer on this question: Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

My build.gradle:

...
  implementation 'com.google.dagger:dagger:2.24'
  annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
  implementation 'com.google.dagger:dagger-android:2.15'
  annotationProcessor 'com.google.dagger:dagger-android-processor:2.24'

After following all of the stated instructions for hours I still got the same error message:

Unable to load class 'dagger.Multibindings'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Since I am actually able to add new dependencies when I remove the following line I suspect the issue might actually be caused by dagger since my gradle was interrupted while I was trying to synchronize new dagger dependencies:

annotationProcessor 'com.google.dagger:dagger-android-processor:2.24'

This problem is really confusing and I need your help! Thank you in advance.

Upvotes: 0

Views: 1660

Answers (1)

Kabir
Kabir

Reputation: 862

// Add Dagger dependencies

dependencies {
  implementation 'com.google.dagger:dagger:2.x'
  annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
}

Example dependencies:

implementation 'com.google.dagger:dagger-android:2.20'
implementation 'com.google.dagger:dagger-android-support:2.20' // if you use the support libraries
annotationProcessor 'com.google.dagger:dagger-android-processor:2.20'
annotationProcessor 'com.google.dagger:dagger-compiler:2.20'

Upvotes: 1

Related Questions