I updated my android studio to latest version flamingo this morning after since I am not able to create a new compose project, getting this below error
No matching variant of com.android.tools.build:gradle:8.0.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.0'
but:
– Variant ‘apiElements’ capability com.android.tools.build:gradle:8.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
– Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
**My App level gradle **
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.abc.myflamingotestapp'
compileSdk 33
defaultConfig {
applicationId "com.abc.myflamingotestapp"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
** Gradle wrapper **
#Mon Apr 17 20:26:41 IST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
** Top level Gradle **
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
getting this issue while trying to build, if anyone else have faced the same issue please help or suggest something.
4
Answers
Since you are using Android API level 33, Java 11 is available through desugaring.
You can now change the source and target compatibility to Java 11:
If you don’t want to change compatibility with version 11 and stay in 1.8, you could desugar it:
first update Gradle to 8.0.0 (at least 4.0.0) modifying build.gradle.kts:
or modifying build.gradle:
as shown in https://developer.android.com/build/releases/gradle-plugin#updating-plugin
Then, desugar it modifying your app’s module build.gradle.kts file:
or your build.gradle Groovy file:
as shown in https://developer.android.com/studio/write/java8-support#library-desugaring.
Remember that you need to remove the -XX:MaxPermSize=1024m argument of jvmargs in gradle.properties file, to avoid an error.
I’ve faced the similar problem
I changed build.gradle(Project: MyProject) to
Change kotlinCompilerExtensionVersion in build.gradle(Module: app) to
And update Gradle JDK to openJDK-19(any ver 11 and above)
Settings screenshot
For me changing only the java version in
build.gradle
file didn’t work. So I changed it in Gradle Settings.Go to
File -> Project Structure -> SDK Location -> Gradle Settings
change Gradle JDK to 17.Click OK and change
compileOptions
andkotlinOptions
to the same version inbuild.gradle(Module:app)
: