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
Ended up changing Gradle JDK to 11.
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
File > Manage IDE Settings > Restore Default Setting
This worked for me on Electric Eel
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.
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.
For Mac users (as @Frederik pointed out), ‘settings’ is ‘Preferences’:
And then:
Finishing:
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
orJava 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)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
alongsideXcode version 14.3
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)
build.gradle(:app)
Gradle JDK settings: