EN VI

Swift - Kotlin Multiplatform Xcode 15.3 Command PhaseScriptExecution failed with a nonzero exit code?

2024-03-15 22:30:09
How to Swift - Kotlin Multiplatform Xcode 15.3 Command PhaseScriptExecution failed with a nonzero exit code

Setup: 2020 MacBook Air M1 8GB // Xcode 15.3 // Android Studio Iguana 2023.2.1

I run into the famous PhaseScriptExecution error while building the "iosAPP" of my KMP project. The error occurs when I try to build via Xcode and Android Studio as well. It does not matter if I create the project directly inside Android Studio or through Jetbrains´ KMP wizard. The error only occurs with the iOS part of the project. I can build and run the App without problems on an Android device or emulator.

I found some workarounds on the internet which advise to change some lines in the framework.sh data. But in my projects there is no framework.sh data. No matter if I init a pod or not. Here is my project (it is just the standard project, created through Android Studio).

Kdoctor is complaining that Cocoapods is not installed, even if it is and works well in standard Xcode projects.

Here are the error messages I get:

Kdoctor

Environment diagnose (to see all details, use -v option):
[✓] Operation System
[✓] Java
[✓] Android Studio
[✓] Xcode
[!] CocoaPods
  ! CocoaPods configuration is not required, but highly recommended for full-fledged development
  ✖ System ruby is currently used
    CocoaPods is not compatible with system ruby installation on Apple M1 computers.
    Please install ruby via Homebrew, rvm, rbenv or other tool and make it default
    Detailed information: https://stackoverflow.com/questions/64901180/how-to-run-cocoapods-on-apple-silicon-m1/66556339#66556339
  ✖ CocoaPods requires your terminal to be using UTF-8 encoding.
    Consider adding the following to ~/.zprofile
    export LC_ALL=en_US.UTF-8

Conclusion:
  ✓ Your operation system is ready for Kotlin Multiplatform Mobile Development!

Xcode build error

Command PhaseScriptExecution failed with a nonzero exit code

Way more detailed Android Studio build error

Too many characters... view here

Solution:

You need to install Java 11 and set it as the version run for the Gradle build. I would just set it to the global default, or possibly version 17.

Check out https://sdkman.io/ to manage multiple Java versions.

The actual error is in here...

* What went wrong:
A problem occurred configuring root project 'KMPDemo'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:8.3.0.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:8.3.0
         project : > com.android.library:com.android.library.gradle.plugin:8.3.0
      > No matching variant of com.android.tools.build:gradle:8.3.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.4' but:
          - Variant 'apiElements' capability com.android.tools.build:gradle:8.3.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
          - Variant 'javadocElements' capability com.android.tools.build:gradle:8.3.0 declares a component for use during runtime, 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 '8.4')
          - Variant 'runtimeElements' capability com.android.tools.build:gradle:8.3.0 declares a library for use during runtime, 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 '8.4')
          - Variant 'sourcesElements' capability com.android.tools.build:gradle:8.3.0 declares a component for use during runtime, 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 '8.4')

Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8

You'll also probably want to install a different ruby version. The system version might work, but you're generally better off with something more up-to-date. I'm using rbenv for that, but there are other options.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login