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

java.lang.IllegalStateException: Unsupported metadata type: kotlinx.metadata.jvm.KotlinClassMetadata$FileFacade #2978

Open GrahamBorland opened 3 years ago

GrahamBorland commented 3 years ago

Dagger 2.40 (also happens with 2.39.1) Kotlin 1.5.31

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

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

I'm getting this crash. I'm trying to add Dagger injection to a Gradle library module which includes an AAC ViewModel. It's very probable I'm doing something wrong (I've been working through a series of Dagger-related build failures), but I don't think it should be causing the Dagger compiler to crash. 😄

What other info would be useful?

Caused by: java.lang.IllegalStateException: Unsupported metadata type: kotlinx.metadata.jvm.KotlinClassMetadata$FileFacade@783e81ec
        at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:213)
        at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:187)
        at dagger.internal.codegen.kotlin.KotlinMetadataFactory.create(KotlinMetadataFactory.java:56)
        at dagger.internal.codegen.kotlin.KotlinMetadataUtil.isObjectClass(KotlinMetadataUtil.java:91)
        at dagger.internal.codegen.validation.InjectValidator.checkInjectIntoKotlinObject(InjectValidator.java:411)
        at dagger.internal.codegen.validation.InjectValidator.validateMembersInjectionType(InjectValidator.java:349)
        at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:315)
        at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterInjectField(InjectBindingRegistryImpl.java:285)
        at dagger.internal.codegen.InjectProcessingStep.process(InjectProcessingStep.java:66)
        at dagger.internal.codegen.validation.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:65)
        at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:185)
        at dagger.internal.codegen.validation.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:55)
        at dagger.internal.codegen.validation.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:40)
        at dagger.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:106)
        at dagger.shaded.androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor.process(JavacBasicAnnotationProcessor.kt:62)
        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:980)

Full error log with stacktrace (gist)

bcorso commented 3 years ago

I think this is due to our processors trying to process an element within a file facade, which we currently don't support.

For example, this would be the case if you had an annotation that we process on a top-level method, like:

// File: Foo.kt

// Invalid top-level usages of @Inject 
@Inject fun invalidInjectMethod(str:String) {}

// Valid usage of @Inject within class
class Foo {
  @Inject fun validInjectMethod(str:String) {}
}

Thanks for bringing this up. We should provide a better error message here.

GrahamBorland commented 3 years ago

@bcorso Thanks, that helped me track down my error. I'd left an @Inject field hanging loose in a file alongside a bunch of @Composable functions.

@Inject
internal lateinit var viewModelFactory: ViewModelProvider.Factory