Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
julioromano opened this issue Jan 29, 2021 · 15 comments
Closed

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

julioromano opened this issue Jan 29, 2021 · 15 comments

Comments

@julioromano
Copy link

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
Copy link
Member

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
Copy link
Author

julioromano commented Jan 29, 2021 via email

@saikiran91
Copy link

saikiran91 commented May 6, 2021

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
Copy link

rohegde7 commented May 6, 2021

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
Copy link

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
Copy link

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
Copy link

michal-th commented May 23, 2021

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
Copy link

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

@micHar
Copy link

micHar commented May 31, 2021

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
Copy link

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

@superus8r
Copy link

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

@danysantiago
Copy link
Member

@k4biri you are seeing a different but similar issue: #2700

@ngengesenior
Copy link

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
Copy link

LeoAndo commented Aug 16, 2021

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
    }

@ericntd
Copy link

ericntd commented Jan 1, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests