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

Gradle crashes with: Hilt + AGP 4.2.0-beta04 #2337

Closed julioromano closed 3 years ago

julioromano commented 3 years ago

Versions: Hilt 2.31.2-alpha AGP 4.2.0-beta04 Gradle 6.8.1

Partial stacktrace:

FAILURE: Build failed with an exception.

* What went wrong:
com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(Lcom/android/build/api/extension/AndroidComponentsExtension;Lcom/android/build/api/extension/VariantSelector;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.NoSuchMethodError: com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(Lcom/android/build/api/extension/AndroidComponentsExtension;Lcom/android/build/api/extension/VariantSelector;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
        at dagger.hilt.android.plugin.HiltGradlePlugin.configureTransformASM(HiltGradlePlugin.kt:224)
        at dagger.hilt.android.plugin.HiltGradlePlugin.configureHilt(HiltGradlePlugin.kt:74)
        at dagger.hilt.android.plugin.HiltGradlePlugin.access$configureHilt(HiltGradlePlugin.kt:47)
        at dagger.hilt.android.plugin.HiltGradlePlugin$apply$1.execute(HiltGradlePlugin.kt:52)
        at dagger.hilt.android.plugin.HiltGradlePlugin$apply$1.execute(HiltGradlePlugin.kt:47)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:100)
        at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction$1.run(DefaultCollectionCallbackActionDecorator.java:95)
danysantiago commented 3 years ago

Looks like the methods got renamed between beta03 and beta04. We'll need to update Hilt's plugin to fix this. Sorry for the inconvenience.

julioromano commented 3 years ago

Fun fact: this doesn't happen with AGP 7.0.0-alpha05 (which was released just one day earlier ).

On Fri, Jan 29, 2021, 17:21 Daniel Santiago notifications@github.com wrote:

Looks like the methods got renamed between beta03 and beta04 https://cs.android.com/android-studio/platform/tools/base/+/25384edea39fc22fc03097fb2e80908bf61b94d1. We'll need to update Hilt's plugin to fix this. Sorry for the inconvenience.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/dagger/issues/2337#issuecomment-769903459, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJW2JEDSX34N5Q25JJXATTS4LN7ZANCNFSM4WYPQZ3Q .

saikiran91 commented 3 years ago
Unable to find method ''void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)''
'void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

It happened to me after upgrading Android Studio to 4.2.0.

Updating the hilt classpath on build.gradle to 2.35 fixed these issues for me.

classpath "com.google.dagger:hilt-android-gradle-plugin:2.35"
rohegde7 commented 3 years ago

Using a combination of

Hilt version 2.35 Android Studio version 4.2 Android Gradle Plugin version 4.2.0 Gradle version to 6.7.1

worked for me

raza-bukhari commented 3 years ago

Please make sure that your hilt version will be same in project level and module level gradle. I've this issue in my project level gradle. I've updated the version to 2.35 in module level but forgot to update it in project-level gradle. It worked for me when I update it in both.

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

masterj3y commented 3 years ago

I got the same error with Hilt 1.0.0 AGP 7.1.0-alpha01 Gradle gradle-7.0-bin

Android Studio Bumblebee | 2021.1.1 Canary 1 Build #AI-203.7717.56.2111.7361063, built on May 14, 2021 Runtime version: 11.0.10+0-b96-7249189 amd64 VM: OpenJDK 64-Bit Server VM by Oracle Corporation Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1280M Cores: 4 Registry: external.system.auto.import.disabled=true Non-Bundled Plugins: org.jetbrains.kotlin

michal-th commented 3 years ago

Same issue encountered in jetpack compose project using:

classpath 'com.android.tools.build:gradle:7.1.0-alpha01'
classpath "com.google.dagger:hilt-android-gradle-plugin:2.35.1"
implementation("com.google.dagger:hilt-android:2.35.1")
kapt("com.google.dagger:hilt-compiler:2.35.1")
kapt 'androidx.hilt:hilt-compiler:1.0.0'

Android Studio Bumblebee | 2021.1.1 Canary 1 Build #AI-203.7717.56.2111.7361063, built on May 14, 2021 Runtime version: 11.0.10+0-b96-7281165 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 11.3.1 GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 16 Registry: external.system.auto.import.disabled=true Non-Bundled Plugins: org.jetbrains.kotlin

UPDATE

by using HEAD-SNAPSHOT the problem is fixed for now (as mentioned here -> #2631)

repositories {
        /*  ...  */
         maven {
            url  "https://oss.sonatype.org/content/repositories/snapshots"
            content {
                includeModule("com.google.dagger", "hilt-android-gradle-plugin")
            }
        }
}

    dependencies {

        classpath "com.google.dagger:hilt-android-gradle-plugin:HEAD-SNAPSHOT"

    }
LloydBlv commented 3 years ago

The problem seems to still exist, the head-snapshot solution by @michal-th did not work either

micHar commented 3 years ago

2.35.1 worked on com.android.tools.build:gradle:7.0.0-beta02, 2.36 works on com.android.tools.build:gradle:7.0.0-beta03

mertceyhan commented 3 years ago

2.36 works on "com.android.tools.build:gradle:7.1.0-alpha02"

superus8r commented 3 years ago

using AGP 7.0.0-beta04 and Hilt 2.37, the same issue seems to persist...

danysantiago commented 3 years ago

@k4biri you are seeing a different but similar issue: https://github.com/google/dagger/issues/2700

ngengesenior commented 3 years ago

using AGP 7.0.0-beta04 and Hilt 2.37, the same issue seems to persist...

Changing to classpath 'com.android.tools.build:gradle:7.1.0-alpha02' should resolve the issue

LeoAndo commented 3 years ago

I solved it with the following gradle settings.

app/build.gradle

dependencies {
    implementation "com.google.dagger:hilt-android:2.37"
    kapt "com.google.dagger:hilt-android-compiler:2.37"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
}

ROOT/build.gradle

    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
        classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
ericntd commented 2 years ago

So is AGP 7 a requirement for Hilt stable to work? (I'm on 6.1.1) Can anyone confirm? 🙏 There's no word about minimum version of AGP here https://dagger.dev/hilt/gradle-setup.html (the documentation of Hilt is otherwise super)