相关文章推荐
刚毅的莴苣  ·  银河麒麟arm64 linux ...·  1 年前    · 
失眠的灭火器  ·  vue+element ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

Electric Eel is weird. First I had this with a Flutter project: stackoverflow.com/questions/51281702/… and then now with an Android project this seems to be also a problem with JDK version. Why did it reset those? – Csaba Toth Jan 16 at 23:34 Note that on macOS the settings are under the "Android Studio" menu. I just selected "Embedded JDK" here, which is the JDK bundled with Android Studio. – Frederik Feb 2 at 12:20 While creating a new project in Electic Eel variant of Android Studio, the mentioned issues arrise. It is basically compelling the developer to use JDK 11 instead of 1.8. Problem will be fixed after doing the same. Thanks – Deepak Rattan Mar 10 at 6:56 Encountered this while trying to run reactivecircus/android-emulator-runner@v2 on github actions. Adding actions/setup-java@v3 before running the emulator runner and setup JDK to 11 solved the issue. – dumbfingers Mar 20 at 12:01

Needed to do two steps...

Change Gradle JDK to 11.

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

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

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)

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

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:

This did not work.. and it actually resets everything from android studio and you need to download all the SDK stuffs again – Jeyaseelan May 31 at 8:00

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.