google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

Exception: Unsupported metadata type: kotlinx.metadata.jvm.KotlinClassMetadata$SyntheticClass #2379

Closed Jeffset closed 2 years ago

Jeffset commented 3 years ago

Build fails with an exception from kapt processing step:

...
Caused by: org.jetbrains.kotlin.kapt3.base.util.KaptBaseError: Exception while annotation processing
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:83)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:34)
        at org.jetbrains.kotlin.kapt3.base.Kapt.kapt(Kapt.kt:45)
        ... 28 more
Caused by: java.lang.IllegalStateException: Unsupported metadata type: kotlinx.metadata.jvm.KotlinClassMetadata$SyntheticClass@6928739
        at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:225)
        at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:196)
        at dagger.internal.codegen.kotlin.KotlinMetadataFactory.create(KotlinMetadataFactory.java:56)
        at dagger.internal.codegen.kotlin.KotlinMetadataUtil.isCompanionObjectClass(KotlinMetadataUtil.java:86)
        at dagger.internal.codegen.validation.BindingMethodValidator$MethodValidator.checkEnclosingElement(BindingMethodValidator.java:169)
        at dagger.internal.codegen.validation.BindingMethodValidator$MethodValidator.checkAdditionalProperties(BindingMethodValidator.java:151)
        at dagger.internal.codegen.validation.BindingElementValidator$ElementValidator.validate(BindingElementValidator.java:153)
        at dagger.internal.codegen.validation.BindingElementValidator$ElementValidator.access$000(BindingElementValidator.java:137)
        at dagger.internal.codegen.validation.BindingElementValidator.validateUncached(BindingElementValidator.java:86)
        at dagger.internal.codegen.base.Util.reentrantComputeIfAbsent(Util.java:33)
        at dagger.internal.codegen.validation.BindingElementValidator.validate(BindingElementValidator.java:82)
        at dagger.internal.codegen.validation.AnyBindingMethodValidator.validateUncached(AnyBindingMethodValidator.java:99)
        at dagger.internal.codegen.base.Util.reentrantComputeIfAbsent(Util.java:33)
        at dagger.internal.codegen.validation.AnyBindingMethodValidator.validate(AnyBindingMethodValidator.java:74)
        at dagger.internal.codegen.validation.BindingMethodProcessingStep.process(BindingMethodProcessingStep.java:58)
        at dagger.internal.codegen.validation.BindingMethodProcessingStep.process(BindingMethodProcessingStep.java:30)
        at dagger.internal.codegen.validation.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:51)
        at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:185)
        at dagger.internal.codegen.validation.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:48)
        at dagger.internal.codegen.validation.TypeCheckingProcessingStep.process(TypeCheckin
...

Dagger version we use is 2.26.1, but the issue persists on 2.32. Kotlin version is 1.4.21

From the basic research I've done, it seems that Dagger still uses old org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.1.0 library version, while 0.2.0 with some new API is released.

So the steps to fix this issue, as I see it, are:

  1. Bump the version in org.jetbrains.kotlinx:kotlinx-metadata-jvm to 0.2.0
  2. Support KotlinClassMetadata.SyntheticClass (and any other new metadata types) in dagger.internal.codegen.kotlin.KotlinMetadata and possibly adapt its use-sites.
Jeffset commented 3 years ago

Update: After further investigation, it seems that the issue has nothing to do with the recent release of rg.jetbrains.kotlinx:kotlinx-metadata-jvm:0.2.0 - SyntheticClass was there from the start. Probably the project code is to blame. I'll probably try to debug Dagger processing our diff and post the results here.

danysantiago commented 3 years ago

The trace shows the SyntheticClass had to be inspected while validating binding method @Provides, @Binds, @Producer, etc. SyntheticClass are generated for a few things but the most likely the case you are running into is a binding method ending on a synthetic class because its an interface default method.

Something like this would cause this:

@Module
interface MyModule {
  @Provides
  fun provide() = "Hello"
}
barry-dempsey commented 3 years ago

This issue looks to have been addressed in release 2.34

zhu1105132453 commented 3 years ago

This issue looks to have been addressed in release 2.34

Modify it to ‘2.34-beta’

dependencies { implementation "com.google.dagger:hilt-android:2.34-beta" kapt "com.google.dagger:hilt-android-compiler:2.34-beta" }

mekutluca commented 3 years ago

In the stable 2.35 version this problem seems to be solved.

dependencies { implementation "com.google.dagger:hilt-android:2.35" kapt "com.google.dagger:hilt-android-compiler:2.35" }

hamzaali6307 commented 3 years ago

In the stable 2.35 version this problem seems to be solved.

dependencies { implementation "com.google.dagger:hilt-android:2.35" kapt "com.google.dagger:hilt-android-compiler:2.35" }

this would saved my time and solved the dagger kotlin conflicts thanks alot