Dagger: @ContributesAndroidInjector broken - nondescript error

Created on 27 Apr 2017  路  26Comments  路  Source: google/dagger

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.

Most helpful comment

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"

All 26 comments

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.

I have the 2nd posts issue as well.

All I would add is that I've been using gradle:2.4.0-alpha6 in a project and have never received this error. However when I went to update another project to include @ContributesAndroidInjector, the error suddenly popped up.

Both use the same gradle and dagger versions. I would assume this means it may not be related to any changes in gradle, but assumptions and all...

If any logs or info is needed just let me know.

@JonathanMerritt You may have run into the error because you upgraded to 2.11, not because of introducing @ContributesAndroidInjector. The error occurs independently of incorporating the annotation in code. And it is definitely related to the Android Gradle plugin version.

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

@ronshapiro you may be exactly right. That is a line not present in the working project and is there in the non working project. I'll test, but I'm guessing it's at least the fix for my issue. Thank you.

@bubenheimer Sorry about the confusion caused. I was only relaying what happened to me and then just made a guess.

Should have checked before posting. I removed that a little while ago. So it's not the problem as far as I know.

I've tried using 2.11rc1 and the head branch. Not sure why or how one project works and the other does not.

@bubenheimer can you file a bug at https://issuetracker.google.com/issues/new?component=192709&template=842921 with your environment, and link to this issue? I can then fill in some information on the Dagger side of things

@ronshapiro Issue created at https://issuetracker.google.com/issues/37741866

My extremely simple Android sample project builds fine with Android Gradle plugin 2.3.x and produces the described error with 2.4.0-alpha6, no other changes.

@ronshapiro please excuse my ignorance, you are saying that the aar on the annotationProcessor is the issue?

Aren't the 2 dependencies that are AAR, dagger-android and dagger-android-support. The others are all jars, this is based on what is up on sonatype for HEAD.

Also, I ended up adding the includeCompileClasspath and that actually fixed the issue for me. The project now builds fine. Using 240 alpha6 and the HEAD, have not tested on 2.11rc1 yet.

Of course I'm guessing this is only a temporary fix since that option is temporary itself inside Gradle.

Tested for 2.11 rc1 and it also builds.

Project for reference JonathanMerritt/BoneDagger

The includeCompileClasspath workaround works for me in isolation, but in my main project that also incorporates other annotation processors I run into other (Guava-related) build issues with this approach.

Can one of you try this with the latest snapshot (or with 2.11-rc2 once it's released in the next few minutes?) I believe it should be fixed

The SNAPSHOT -jarimpl works for me. I can check rc2 whenever I see it up.

Thanks for the quick fix @ronshapiro

When I build the test project that I referenced in the Google issue I now get this error when building with RC2:

error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider dagger.internal.codegen.ComponentProcessor could not be instantiated: java.lang.NoClassDefFoundError: com/google/common/collect/SetMultimap

In my main project I see the following now without even referencing dagger-android-processor; RC2 is less usable for me than RC1, I am unable to build now.

Execution failed for task ':app:compileNormalCheckDebugJavaWithJavac'.
> java.lang.NoClassDefFoundError: dagger/producers/Produces

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.

"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.

I have same problem. I already added annotationProcessor "com.google.dagger:dagger-android-processor:2.11-rc2" to project but still i get this error. any advices? thanks.

@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.

Use 2.11 these days, not 2.11-rc2

thanks for your replies. i'm already using 2.11 i'm trying to use Dagger with kotlin and i think i'm missing stg about Kotlin.

Edit: I solved my problem. i'm missing the point @spookyUnknownUser mentioned in last comment. thanks.

Have anyone tried to use Dagger 2 for Espresso tests? I'm trying to generate a dedicated test component under androidTest directory but getting this error:

Error:Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Provider dagger.android.processor.AndroidProcessor could not be instantiated: java.lang.NoClassDefFoundError: com/google/common/collect/SetMultimap

Here's how dependencies look like:

androidTestCompile "com.google.dagger:dagger:2.11",
androidTestCompile "com.google.dagger:dagger-android:2.11"
androidTestCompile  "com.google.dagger:dagger-android-support:2.11"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.11"
androidTestAnnotationProcessor "com.google.dagger:dagger-android-processor:2.11"

Thanks

@alekseichuk this is working for me for version 2.11

compile 'com.google.dagger:dagger:' + rootProject.ext.daggerVersion
annotationProcessor 'com.google.dagger:dagger-compiler:' + rootProject.ext.daggerVersion
testAnnotationProcessor 'com.google.dagger:dagger-compiler:' + rootProject.ext.daggerVersion
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:' + rootProject.ext.daggerVersion
compile "com.google.dagger:dagger-android:" + rootProject.ext.daggerVersion
compile "com.google.dagger:dagger-android-support:" + rootProject.ext.daggerVersion
annotationProcessor 'com.google.dagger:dagger-android-processor:' + rootProject.ext.daggerVersion
androidTestAnnotationProcessor 'com.google.dagger:dagger-android-processor:' + rootProject.ext.daggerVersion

I have an EspressoComponent that provides its own Modules, including a different BindingModule (the one with @ContributesAndroidInjector)

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"

convert fragmentBuilderModule in java
this is not run in kotlin so convert your class in java and enjoy

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"

Thank you while(true) println(very) much! i like kapt, it'd solved the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SteinerOk picture SteinerOk  路  3Comments

rciovati picture rciovati  路  3Comments

blackberry2016 picture blackberry2016  路  3Comments

makaroffandrey picture makaroffandrey  路  3Comments

pyricau picture pyricau  路  4Comments