dagger: @ContributesAndroidInjector broken - nondescript error

Tried to use @ContributesAndroidInjector in a simplistic sample project but failed and no idea what the problem is. The sole build error is

dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
interface AppComponent extends AndroidInjector<MainApplication> {
^
1 error

I followed the documentation in creating my sample code. I have no errors when I replace the @ContributesAndroidInjector with the equivalent old-style code.

Same issue with UsesGeneratedModulesApplication from the Dagger repository, at least when I build it in a Gradle project.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26

Commits related to this issue

Most upvoted comments

“Just incase anyone as dumb as me also comes across this thread”

Another dumbass in the party. You’re my life savior! I’m struggling since several hours! Who could expect that @ContributesAndroidInjector requires a separate artifact! If anyone in future sees the error message componentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. the above could be the cause.

Guys, I’m using kotlin in android studio. What was causing this error was because i was using annotationProcessor instead of kapt

 //dagger
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion" // if you use the support libraries
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"

Can you see the last line of code above? yah that one made me struggle for like 2 days. so,as i said, what was needed is kotlin application processing tool. a.k.a kapt and not annotationProcessor

//dagger
    implementation "com.google.dagger:dagger:$daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$daggerVersion"
    implementation "com.google.dagger:dagger-android:$daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$daggerVersion" // if you use the support libraries
    kapt "com.google.dagger:dagger-android-processor:$daggerVersion"

This might be dumb, but I got the same error by forgetting to include

annotationProcessor "com.google.dagger:dagger-android-processor:2.11"

in my build.gradle dependencies.

Just incase anyone as dumb as me also comes across this thread as the top google result, including android-processor as a dependency fixed the error.

The error occured because I was not using

annotationProcessor 'com.google.dagger:dagger-android-processor:2.11-rc1'

So far I was able to get away without this dependency. Would have been nice to see an error pointing in the right direction.

There is a related problem, though, when including dagger-android-processor and using com.android.tools.build:gradle:2.4.0-alpha6 instead of 2.3.1 or 2.3.2:

Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.NoClassDefFoundError: dagger/android/ContributesAndroidInjector

There were some changes in 2.4 to how annotation processors are handled.

Use 2.11 these days, not 2.11-rc2

@savepopulation I just wrote annotationProcessor to mean your annotation processor here

Be sure that you’re using annotationProcessor for your other annotation libraries as well. It might also be apt or kapt.

Tested for 2.11 rc1 and it also builds.

Project for reference JonathanMerritt/BoneDagger

Someone reported that they get the same error on 2.3.x “when using includeCompileClasspath”. I believe the issue is that the gradle plugin doesn’t know how to load an aar on the annotationProcessor path