google / dagger

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

Support for Kotlin 1.5.20 #2684

Closed Jeff11 closed 3 years ago

Jeff11 commented 3 years ago

With Kotlin 1.5.20-RC I get this error.

Works with Kotlin 1.5.10.

Dagger version 2.37

/Users/username/projects/myproject/appname/build/tmp/kapt3/stubs/devAppnameDebug/de/company/appname/ApplicationMain.java:47: error: [Hilt]
public final class ApplicationMain extends company.appname.ApplicationBase {
             ^
  Expected @HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
  See https://dagger.dev/hilt/gradle-setup.html
  [Hilt] Processing did not complete. See error above for details.
/Users/username/projects/myproject/appname/build/tmp/kapt3/stubs/devAppnameDebug/de/company/appname/ui/SecondFragment.java:43: error: [Hilt]
public final class SecondFragment extends company.appname.ui.base.BaseFragment {
             ^
  Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin)
  See https://dagger.dev/hilt/gradle-setup.html
  [Hilt] Processing did not complete. See error above for details.
bcorso commented 3 years ago

Did you forget to apply the Gradle Plugin (dagger.hilt.android.plugin)?

Jeff11 commented 3 years ago

I am using the Gradle plugin. Until Kotlin 1.5.10 there are no problems with the build. It just started with 1.5.20-M1 and -RC.

I can switch to 1.5.10 and the build will work.

burhankhanzada commented 3 years ago

i also have this issue and @jeff11 is rith its working fine with 1.5.10

SteinerOk commented 3 years ago

Also with 1.5.20-RC not working compiler argument for disabling InstallIn check:

        javaCompileOptions {
            annotationProcessorOptions {
                arguments += [
                        "dagger.hilt.disableModulesHaveInstallInCheck": "true"
                ]
            }
        }
bcorso commented 3 years ago

This sounds like a bug in the kotlin/kapt plugin rather than Hilt. In particular, javaCompilerOptions.annotationProcessorOptions are just getting ignored in general, as mentioned in https://github.com/google/dagger/issues/2684#issuecomment-860175674. This ends up causing Hilt to fail because the Hilt Gradle plugin sets these options in HiltGradlePlugin.kt.

FWIW, it looks like the processing options set through kapt.javacOptions do still work, so as a workaround you can set the options manually:

kapt {
    javacOptions {
        // These options are normally set automatically via the Hilt Gradle plugin, but we
        // set them manually to workaround a bug in the Kotlin 1.5.20
        option("-Adagger.fastInit=ENABLED")
        option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
    }
}
slavonnet commented 3 years ago

kapt.use.worker.api=false fixes many strange issues from kapt

bcorso commented 3 years ago

I've filed a bug with kotlin here: https://youtrack.jetbrains.com/issue/KT-47416

SerggioC commented 3 years ago

kapt.use.worker.api=false fixes many strange issues from kapt

It'll decrease build speed though: https://kotlinlang.org/docs/kapt.html#improving-the-speed-of-builds-that-use-kapt

To improve the speed of builds that use kapt, you can enable the Gradle worker API for kapt tasks. Using the worker API lets Gradle run independent annotation processing tasks from a single project in parallel, which in some cases significantly decreases the execution time.

@bcorso sulution works. 👍

mmathieum commented 3 years ago

Kotlin 1.5.21 fixes the issue for me https://github.com/JetBrains/kotlin/releases/tag/v1.5.21