Hattip to a comment from @chrisjenx for pointing out the fix needed: #226 (comment)
Our code worked with dagger 2.41, but NOT with 2.42
The error message (below) does not give you much help as to what the problem is.
My request is for a more helpful error message in this scenario, but also documenting the solution for those that may encounter it in the future.
If you are missing some required api dependencies (but they are pulled in transitively at runtime), then dagger may give a compile error similar to this.
The solution is to add whatever required api dependencies that your build is missing.
As an example:
api "androidx.fragment:fragment:1.3.4"
api "com.google.android.gms:play-services-maps:17.0.1"
You can use https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin to help you identify your missing dependencies.
It seems that this code can not properly detect supertypes if there are missing api dependencies:
|
public static Optional<XType> nonObjectSuperclass(XType type) { |
|
return isDeclared(type) |
|
? type.getSuperTypes().stream() |
|
.filter(supertype -> !supertype.getTypeName().equals(TypeName.OBJECT)) |
|
.filter(supertype -> isDeclared(supertype) && supertype.getTypeElement().isClass()) |
|
.collect(toOptional()) |
|
: Optional.empty(); |
|
} |
Compile time error message:
Caused by: com.sun.tools.javac.processing.AnnotationProcessingError: java.lang.IllegalArgumentException: expected one element but was: <com.example.MyFragment, com.google.android.gms.maps.OnMapReadyCallback>
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1035)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:939)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1267)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1382)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1234)
... 40 more
Caused by: java.lang.IllegalArgumentException: expected one element but was: <com.example.MyFragment, com.google.android.gms.maps.OnMapReadyCallback>
at dagger.internal.codegen.extension.DaggerCollectors$ToOptionalState.multiples(DaggerCollectors.java:97)
at dagger.internal.codegen.extension.DaggerCollectors$ToOptionalState.getOptional(DaggerCollectors.java:139)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:686)
at dagger.internal.codegen.xprocessing.XTypes.nonObjectSuperclass(XTypes.java:116)
at dagger.internal.codegen.binding.InjectionSiteFactory.getInjectionSites(InjectionSiteFactory.java:72)
at dagger.internal.codegen.binding.BindingFactory.membersInjectionBinding(BindingFactory.java:522)
at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:318)
at dagger.internal.codegen.validation.InjectBindingRegistryImpl.getOrFindMembersInjectionBinding(InjectBindingRegistryImpl.java:367)
at dagger.internal.codegen.validation.InjectBindingRegistryImpl.getOrFindMembersInjectorProvisionBinding(InjectBindingRegistryImpl.java:378)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.lookUpBindings(BindingGraphFactory.java:409)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolve(BindingGraphFactory.java:813)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolveDependencies(BindingGraphFactory.java:828)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolve(BindingGraphFactory.java:815)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolveDependencies(BindingGraphFactory.java:828)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolve(BindingGraphFactory.java:815)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolveDependencies(BindingGraphFactory.java:828)
at dagger.internal.codegen.binding.BindingGraphFactory$Resolver.resolve(BindingGraphFactory.java:815)
at dagger.internal.codegen.binding.BindingGraphFactory.lambda$createLegacyBindingGraph$5(BindingGraphFactory.java:210)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at dagger.internal.codegen.binding.BindingGraphFactory.createLegacyBindingGraph(BindingGraphFactory.java:205)
at dagger.internal.codegen.binding.BindingGraphFactory.createLegacyBindingGraph(BindingGraphFactory.java:234)
at dagger.internal.codegen.binding.BindingGraphFactory.create(BindingGraphFactory.java:112)
at dagger.internal.codegen.ComponentProcessingStep.processRootComponent(ComponentProcessingStep.java:110)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:88)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:50)
at dagger.internal.codegen.validation.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:79)
at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:196)
at dagger.internal.codegen.validation.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:69)
at dagger.internal.codegen.validation.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:47)
at dagger.spi.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:59)
at dagger.spi.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:123)
at dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor.process(JavacBasicAnnotationProcessor.kt:71)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt:90)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:188)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1023)
... 44 more```
Hattip to a comment from @chrisjenx for pointing out the fix needed: #226 (comment)
Our code worked with dagger
2.41, but NOT with2.42The error message (below) does not give you much help as to what the problem is.
My request is for a more helpful error message in this scenario, but also documenting the solution for those that may encounter it in the future.
If you are missing some required
apidependencies (but they are pulled in transitively at runtime), then dagger may give a compile error similar to this.The solution is to add whatever required
apidependencies that your build is missing.As an example:
You can use https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin to help you identify your missing dependencies.
It seems that this code can not properly detect supertypes if there are missing
apidependencies:dagger/java/dagger/internal/codegen/xprocessing/XTypes.java
Lines 111 to 118 in b0aa9f1
Compile time error message: