Unable to find method ''void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build
AndroidKotlinAndroid Problem Overview
my first project using Jetpack Compose got an error like this, how can I fix it
> 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.)
My dependencies:
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-beta03'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.31.2-alpha"
}
Android Solutions
Solution 1 - Android
In my case the problem was incompatibility between Android Gradle Plugin and Hilt library. After upgrading Hilt to the latest version, I can also use the latest AGP.
[EDIT]
It seems that recent release of Android Gradle Plugin has fixed the issue and
AGP version 7.0.0-beta05
works with Hilt version 2.37
.
Solution 2 - Android
In my case AGP 7.0.0
builded successfully with Hilt 2.37
Solution 3 - Android
If you are using Hilt, upgrade it to v2.38.1 . Some problems with AGP 7 has been fixed in this release
See here : https://github.com/google/dagger/releases
Solution 4 - Android
For me, I was used
Gradle
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
Hilt
Projet level gradle
classpath "com.google.dagger:hilt-android-gradle-plugin:2.39.1"
App level gradle
implementation "com.google.dagger:hilt-android:2.39.1"
kapt "com.google.dagger:hilt-compiler:2.39.1"
androidTestImplementation "com.google.dagger:hilt-android-testing:2.39.1"
kaptAndroidTest "com.google.dagger:hilt-android-compiler:2.39.1"
Solution 5 - Android
[UPDATE]: Currently, u can use Hilt 2.38
with gradle:7.1.0
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
if it doesn't work, let me know
Solution 6 - Android
use the gradle plugin for Hilt 2.39.1:
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.39.1'
and update the hilt version to 2.37:
implementation "com.google.dagger:hilt-android:2.37"
kapt "com.google.dagger:hilt-android-compiler:2.37"
Solution 7 - Android
just update to latest version of dagger hilt i,e, currently(2.38.1)
Solution 8 - Android
Use this dependency to your build.gradle file
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
classpath "io.realm:realm-gradle-plugin:10.4.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.35"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
Solution 9 - Android
Use Android Gradle plugin (AGP) version 7.0.3
+, for instance 7.1.0-rc01
or 7.2.0-alpha06
check in project level build gradle config
plugins {
id("com.android.application") version "7.0.4" apply false
id("org.jetbrains.kotlin.android") version "1.6.10" apply false
id("com.android.library") version "7.0.4" apply false
}
buildscript {
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
}
}
Solution 10 - Android
Updating hilt version to latest worked for me.
def hilt_version = '2.39.1'
Solution 11 - Android
I was faced this same issue here is my changes
- kotlin_version = "1.6.10" // was "1.5.21"
- hilt_version = '2.39.1' // was "2.37"
- gradle 7.1.0-rc01
Solution 12 - Android
in my solution , this work fine
- kotlin_version = "1.6.10"
- gradle-7.3
- gradle:7.0.4 ( plugin )
- com.google.dagger:hilt-android-gradle-plugin:2.37**