skip to Main Content

I’ve just created a brand new material 3 compose project and this pops up:

> No matching variant of com.android.tools.build:gradle:7.4.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')

Didn’t change anything, everything is the default.

7

Answers


  1. Chosen as BEST ANSWER

    Ended up changing Gradle JDK to 11.

    File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle


  2. File > Manage IDE Settings > Restore Default Setting

    This worked for me on Electric Eel

    Login or Signup to reply.
  3. It also happened to me and the only option I found was to reinstall the project. When reinstalling I exported the settings and when it happens again I import them.

    Login or Signup to reply.
  4. Needed to do two steps…

    Change Gradle JDK to 11.

    File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle

    then

    File -> Repair IDE.
    Ran through each of the steps until it restarted and then started downloading a load of files. Build worked after this.

    Login or Signup to reply.
  5. For Mac users (as @Frederik pointed out), ‘settings’ is ‘Preferences’:
    Preferences location

    And then:
    enter image description here
    Finishing:
    enter image description here

    Login or Signup to reply.
  6. If on Kotlin Multiplatform (KMM) upgrade to Java 17.

    When you create a new KMM project Android Studio’s Gradle build setting auto-defaults to Java 1.8 (or whatever is specified for JAVA_HOME or org.gradle.java.jome).

    If you upgrade to Java 11 or Java 13 it’ll build successfully and run on Android Studio but it won’t Build or Run successfully on Xcode.

    The way around (it seems) is to go up one more version to Java 17 (Amazon’s corretto-17 in my case)

    corretto-17

    It seemed like using a version lower than 17 was breaking the expected Gradle plugin version in Xcode (but only on Xcode) – which introduces scope issues with the shared folder.


    Tested when creating a new project with CocoaPods and with Regular Framework.

    Tested on Android Studio Flamingo alongside Xcode version 14.3

    Login or Signup to reply.
  7. If you make adjustments like this in the latest version Android Studio Flamingo | 2022.2.1, you will not have any problems.

    build.gradle(project)

    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.8.0' apply false
    }
    

    build.gradle(:app)

    ...
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        kotlinOptions {
            jvmTarget = '1.8'
        }
    ...
    

    Gradle JDK settings:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search