skip to Main Content

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


  1. 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:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    
    kotlin {
        jvmToolchain(11)
    }
    
    Login or Signup to reply.
  2. 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:

    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
    }
    

    or modifying build.gradle:

    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
    }
    

    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:

    android {
        defaultConfig {
            // Required when setting minSdkVersion to 20 or lower
            multiDexEnabled = true
        }
    
        compileOptions {
            // Flag to enable support for the new language APIs
    
            // For AGP 4.1+
            isCoreLibraryDesugaringEnabled = true
            // For AGP 4.0
            // coreLibraryDesugaringEnabled = true
    
            // Sets Java compatibility to Java 8
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
        }
    }
    
    dependencies {
        coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.2.2")
    }
    

    or your build.gradle Groovy file:

    android {
        defaultConfig {
            // Required when setting minSdkVersion to 20 or lower
            multiDexEnabled true
        }
    
        compileOptions {
            // Flag to enable support for the new language APIs
            coreLibraryDesugaringEnabled true
            // Sets Java compatibility to Java 8
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    dependencies {
        coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
    }
    

    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.

    Login or Signup to reply.
  3. I’ve faced the similar problem

    I changed build.gradle(Project: MyProject) to

    plugins {
        id 'com.android.application' version '7.3.1' apply false
        id 'com.android.library' version '7.3.1' apply false
        id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
        id 'org.jetbrains.kotlin.jvm' version '1.8.10' apply false
    }
    

    Change kotlinCompilerExtensionVersion in build.gradle(Module: app) to

    composeOptions {
                    kotlinCompilerExtensionVersion '1.4.3'
                }
    

    And update Gradle JDK to openJDK-19(any ver 11 and above)
    Settings screenshot

    Login or Signup to reply.
  4. 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.

    enter image description here

    Click OK and change compileOptions and kotlinOptions to the same version in build.gradle(Module:app):

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    
    kotlinOptions {
        jvmTarget = '17'
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search