我跟着Get started with Kotlin Multiplatform Mobile 逐步形式 *1.设置环境 * 到 *2.创建您的第一个跨平台应用 *。对于iOS,我选择了默认框架,而不是可可pod,因为这是一个Hello world项目。
在运行Android应用程序时,我遇到了一些与模拟器相关的问题,这些问题通过更新存储大小得到了解决。但当我运行iOS应用程序时,我遇到了这样的问题:
命令PhaseScriptExecution失败,退出代码为非零
完整的异常日志:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'POCKMHelloWorld'.
Could not resolve all files for configuration ':classpath'.
Could not resolve com.android.tools.build:gradle:7.4.2.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:7.4.2
project : > com.android.library:com.android.library.gradle.plugin:7.4.2
> No matching variant of com.android.tools.build:gradle:7.4.2 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.2 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.2 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.2 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.2 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')
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Run\ Script /Users/arpit/Work/Arpit/KotlinMultiplateform/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Script-7555FFB5242A651A00829871.sh (in target 'iosApp' from project 'iosApp')
(1 failure)
配置:
MacOS Xcode版本14.2(14C18)
Android Studio 电鳗|2022.1.1修补程序2
我尝试过的:
- 根据建议更新了build.gradle.kts中的gradle配置,之后回滚了这些配置
- 在android设备管理器中更新设备和配置
- 安装
kdoctor
检查配置是否正确,显示为
1条答案
按热度按时间ajsxfq5m1#
如果您安装了java和Oracle dmg,它的版本与运行iOS的预期Kotlin多平台插件的版本不同。要了解您是否安装了oracle java,请打开终端窗口并键入以下命令:
您应看到类似于以下内容的结果:
正如Robert Naggy在他的回答here中提到的,我们需要Java 11来运行iOS应用程序。
现在从brew安装Open Java:
如果您现在运行应用程序,它仍然会给予与我们需要在库中设置符号链接相同的错误。为此,请注意安装日志末尾的说明。
要使系统Java Package 器找到此JDK,请使用sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /库/Java/JavaVirtualMachines/openjdk-11.jdk对其进行符号链接
除了许多其他的事情,所以运行这个命令:
从菜单选项
Build > Rebuild Project
,Build Now重建项目,您应该能够运行iOS应用程序。