dagger: Gradle crashes with: Hilt + AGP 4.2.0-beta04

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)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 35
  • Comments: 15 (2 by maintainers)

Most upvoted comments

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

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

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"

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

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

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"
        
    }

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 .

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

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

I solved it with the following gradle settings.

  • dagger hilt : 2.37
  • AGP : 7.0.0

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
    }

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