4

I've just created a new KMM project through out KMM Plugin, but I can't run or even debug in Xcode iosApp part of the project. When I try to run iosApp from Android Studio, the build process fails (Command PhaseScriptExecution failed with nonzero exit code)

The final lines of building was:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':shared:compileKotlinIosX64'.

Compilation finished with errors

  • 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 1 actionable task: 1 executed Command PhaseScriptExecution failed with a nonzero exit code

** BUILD FAILED **

The following build commands failed: PhaseScriptExecution Run\ Script /Users/tamegajr/AndroidStudioProjects/TesteKMM5/build/ios/iosApp.build/Release-iphonesimulator/iosApp.build/Script-7555FFB5242A651A00829871.sh (1 failure)

Can anyone help to solve this problem?

tamegajr
  • 55
  • 5

6 Answers6

1

i just installed the jvm 17 from oracle website and the problem solved

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 08 '23 at 20:42
1

Working/Tested on - 01 July 2023

What worked for me ?

  1. Open Android Studio Settings/Preferences

    MAC Users - Android Studio -> Settings

or cmd + ,

  1. Search for "Gradle"

  2. In the Gradle JDK dropdown, select Oracle Open JDK-20 If you don't see Oracle Open JDK 20 - then select Download JDK option and download the version 20.

  3. Sync the Gradle and you are done!

Hope it helps someone...

1

In my case XCode's JAVA_HOME variable caused the problem.

  1. Open project on XCode
  2. Open iosApp.xcodeproj on sidepanel
  3. Select BuildPhases
  4. Expand "Run Script"

Add this two lines into Build Script, before gradlew tasks. (I've used Android Studio's built-in JDK. If you want to use another JDK, you should change JAVA_HOME and JDK_HOME paths in code below.)

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home/
export JDK_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/

Your final Build Script should be like this;

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home/
export JDK_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/

cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode
Emirhan Soylu
  • 681
  • 6
  • 12
0

What i found to be the solution was to uncomment the "iosSimulatorArm64()" in the "build.gradle.kts(:shared)".

kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64() //sure all ios dependencies support this target

cocoapods {
    summary = "Some description for the Shared Module"
    homepage = "Link to the Shared Module homepage"
    ios.deploymentTarget = "14.1"
    podfile = project.file("../iosLink/Podfile")
    framework {
        baseName = "shared"
    }
}

sourceSets {
    val commonMain by getting
    val commonTest by getting {
        dependencies {
            implementation(kotlin("test-common"))
            implementation(kotlin("test-annotations-common"))
        }
    }
    val androidMain by getting
    val androidTest by getting {
        dependencies {
            implementation(kotlin("test-junit"))
            implementation("junit:junit:4.13.2")
        }
    }
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
        dependsOn(commonMain)
        iosX64Main.dependsOn(this)
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
    }
    val iosX64Test by getting
    val iosArm64Test by getting
    //val iosSimulatorArm64Test by getting
    val iosTest by creating {
        dependsOn(commonTest)
        iosX64Test.dependsOn(this)
        iosArm64Test.dependsOn(this)
        //iosSimulatorArm64Test.dependsOn(this)
    }
}

}

0

For me the problem was, that even though I set everywhere in AndroidStudio and in the build.gradle files to use java 11, it still tried to use java 1.8 instead.
Then I looked into the project's gradlew file and found out, that it uses the JAVA_HOME path variable.

Because I have other projects and those use java 1.8, I have a JAVA_HOME variable set to 1.8 in the .zshrc file.
I changed this to 11 (which I downloaded earlier), restarted AndroidStudio - with Invalidate caches and restart, just to be sure -, and it instantly worked.
I was able to run the code in an iOS simulator from AndroidStudio.

On Mac, in the .zhsrc file I wrote

before:
export JAVA_HOME=/Users/username/Library/Java/JavaVirtualMachines/corretto-1.8.0_292/Contents/Home

after:
export JAVA_HOME=/Users/username/Library/Java/JavaVirtualMachines/corretto-11.0.18/Contents/Home

If you use other Java version in your project, you have to set its version number in the JAVA_HOME variable. Also check the path for the Library/Java/... folder. If it's different from the above, then change it accordingly.

katazina
  • 11
  • 2
-2

After some code review from 2-3 months old KMM examples project and comparing them with new ones, I found out a solution for this build failure when trying to run iosApp on Ios Simulators, just apply this change to build.gradle.kts on root project:

From KMM pluging you will obtain (on dependencies):

classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")

Change it to:

classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")

And that's it, problem solve. I hope someone on Jetbrains can solve this problem in future updates of KMM plugin.

08/30/2020:

It seems that Jetbrains has correct some issues and now you can build and run a KMM project with version 1.7.10, the last stable version at this time.

By the way, if you have any trouble is worthy to check this stack overflow post about JDK version used by Android Studio : How to set or change the default Java (JDK) version on macOS?

Multiplatform error when building iosApp: Command PhaseScriptExecution failed with a nonzero exit code

tamegajr
  • 55
  • 5