dagger: Dagger-2.17 An exception occurred: java.util.NoSuchElementException

e: [kapt] An exception occurred: java.util.NoSuchElementException
	at com.sun.tools.javac.util.List$2.next(List.java:432)
	at com.google.common.collect.Iterators.getOnlyElement(Iterators.java:302)
	at com.google.common.collect.Iterables.getOnlyElement(Iterables.java:254)
	at dagger.android.processor.AndroidMapKeys.mapKeyValue(AndroidMapKeys.java:75)
	at dagger.android.processor.AndroidMapKeys.lambda$annotationsAndFrameworkTypes$5(AndroidMapKeys.java:56)
	at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1321)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 54
  • Comments: 38

Commits related to this issue

Most upvoted comments

To confirm, v2.16 works fine. Only happens when switching to v2.17

I have same issue with dagger 2.17 and and gradle plugin 3.3.0-alpha05. With 2.16 it works fine.

Seems like this error is persisting into 2.18

I’m also running into this issue, specifically when trying to switch to AndroidX dependencies. I’ve created a minimal repro in tkindy/dagger-androidx-bug (instructions in README).

Any ETA regarding a fix?

It seems to be an (indirect) issue with the Android Gradle Plugin 3.2.0-beta05. The problem occurs even in an empty project, with a single empty Activity, without any Dagger @Component, @Module, …

It does not occur with Android Gradle Plugin 3.1.4.

build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    ...
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation "com.google.dagger:dagger:${dagger_version}"
    kapt "com.google.dagger:dagger-compiler:${dagger_version}"
    implementation "com.google.dagger:dagger-android:${dagger_version}"
    implementation "com.google.dagger:dagger-android-support:${dagger_version}"
    kapt "com.google.dagger:dagger-android-processor:${dagger_version}"
}

It can also be observed that, with 3.2.0-beta05, the dependency resolution is strange. I can’t tell where the 2.16 comes from.

$ gradlew app:dependencies --configuration kapt

kapt
...
\--- com.google.dagger:dagger-android-processor:2.17 -> 2.16
     +--- com.google.dagger:dagger:2.16 -> 2.17 (*)
     +--- com.google.dagger:dagger-android-jarimpl:2.16
     +--- com.google.dagger:dagger-android-support-jarimpl:2.16
...

With 3.1.4, it looks more as expected:

$ gradlew app:dependencies --configuration kapt

kapt
...
\--- com.google.dagger:dagger-android-processor:2.17
     +--- com.google.dagger:dagger:2.17 (*)
     +--- com.google.dagger:dagger-android-jarimpl:2.17
     |    +--- com.google.dagger:dagger:2.17 (*)
     |    +--- com.android.support:support-annotations:25.0.0
     |    \--- javax.inject:javax.inject:1
     +--- com.google.dagger:dagger-android-support-jarimpl:2.17
     |    +--- com.google.dagger:dagger:2.17 (*)
     |    +--- com.google.dagger:dagger-android:2.17
     |    |    +--- com.google.dagger:dagger:2.17 (*)
...

Everything works like charm again. I had issues with other xml support widgets that were causing the build to fail before it reaches Dagger. When those issues are fixed, the jetifier worked well and the project compiled. Thanks for the help @tasomaniac

I mentioned this line of the Jetifier sources that I found which prevents the 2.17 upgrade. I also briefly tried to change that config file inside the jetifier jar. It had the desired effect (working 2.17 dependencies) but this resulted in a different error. Unfortunately, I’m traveling right now and don’t have more details at hand.

Edit: In fact, patching the config files of jetifier-core-1.0.0-alpha10.jar worked fine to get dagger 2.17 working. Any additional issues I ran into were simply those explained in the 2.17 changelog.