0

I followed Get started with Kotlin Multiplatform Mobile step-by-step form 1. Set up an Environment to 2. Create your first cross-platform app. For iOS I opted for default frameworks instead of the cocoa pod as this one is a Hello world Project.

While running the android application I faced some Emulator-related issues which were resolved by updating the storage size. But when I am running an iOS application I face the issue that says:

Command PhaseScriptExecution failed with a nonzero exit code

Complete exception log:

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)

Configurations:

MacOS Xcode Version 14.2 (14C18)
Android Studio Electric Eel | 2022.1.1 Patch 2

What I have tried:

  • Updated gradle configuration in build.gradle.kts based on suggestions, rolled those back afterward
  • Updating devices and configurations in the android device manager
  • Installed kdoctor to check whether the configuration was right and it showed it was enter image description here
rptwsthi
  • 10,094
  • 10
  • 68
  • 109

1 Answers1

0

If you have java installed with Oracle dmg, it has a different version than what is expected kotlin multiplatform plugin to run iOS. To know if you have oracle java, open the terminal window and type this command:

~ % java -version

You should see result similar to this:

java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)

As Robert Naggy mentions in his answer here, we need Java 11 to run iOS applications.

Now install Open Java from brew:

~ % brew install openjdk@11

If you run the application now, it will still give the same error as we need to set the symlink in Library. To do that pay attention to the instructions at the end of the installation log. It says:

For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

In addition to many other things, so run this command:

~ % sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

Rebuild your project from the menu options Build > Rebuild Project, Build Now you should be able to run the iOS application.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109