运行iOs应用程序时出现Kotlin多平台默认项目错误:无法解析com.android.tools.build:升级版:7.4.0-rc 01

jgzswidk  于 2022-12-23  发布在  Kotlin
关注(0)|答案(1)|浏览(605)

bounty将在5天后过期。回答此问题可获得+300声望奖励。Siavash希望引起更多人对此问题的关注:这个问题是在Kotlin多平台的背景下,而不是一个一般的android问题。寻找一个答案,让我可以运行由android studio创建的default KMP project,在ios模拟器。理想情况下,通过点击运行在android studio(与iOS运行配置)。

我创建了一个默认的KMP项目,没有做任何更改。它在Android上运行良好,但当我尝试在iOS上运行它时,它告诉我它找不到gradle插件:

A problem occurred configuring root project 'KMPSandBox'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.0-rc01.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.0-rc01
         project : > com.android.library:com.android.library.gradle.plugin:7.4.0-rc01
      > No matching variant of com.android.tools.build:gradle:7.4.0-rc01 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-rc01 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-rc01 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')
flvlnr44

flvlnr441#

在我看来,您似乎安装了不兼容的JDK,或者至少在Gradle构建脚本中定位了错误的JDK。
请查看Gradle设置。

下面的错误行给出了以下提示:

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

从Gradle 7.3.0开始,最低JDK版本为11。

https://developer.android.com/studio/releases/gradle-plugin#compatibility-7-3-0
您能检查一下是否安装了JDK 11吗?
如果您的app/build.gradle.kts(或build.gradle -如果您使用Groovy)中有这些行,并且它们可能是在Java 8上,我个人总是倾向于在脚本文件中显式设置这些行,而不依赖于默认行为。

compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

否则,默认值为:
默认情况下,用于编译项目的Java语言版本基于项目的compileSdkVersion,因为不同版本的Android支持不同版本的Java。如有必要,您可以通过向build.gradle文件添加以下compileOptions块来覆盖此默认Java版本。https://developer.android.com/studio/intro/studio-config#jdk

相关问题