https://kotlinlang.org logo
Title
j

Jan

04/19/2023, 10:06 AM
Hi, I am using Kotlin Multiplatform to build iOS/Android App. Recently I just updated to Gradle 8.0.0 due update of AndroidStudio from Electric Eel to Flamingo. Starting the iOS Project from AndroidStudio is working fine. Right now I do have a problem to run my iOS Project from Xcode (14.3). Building the ios framework fails with: "Android Gradle plugin requires Java 17 to run. You are currently using Java 11. ... Your current JDK is located in /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home". I do not understand why XCode has a different JDK. In my .zshr file its defined like: export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home and if I check ./gradlew -v it says: Gradle 8.0 ------------------------------------------------------------ Build time: 2023-02-13 13:15:21 UTC Revision: 62ab9b7c7f884426cf79fbedcf07658b2dbe9e97 Kotlin: 1.8.10 Groovy: 3.0.13 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 17.0.6 (JetBrains s.r.o. 17.0.6+0-17.0.6b802.4-9586694) OS: Mac OS X 13.0.1 aarch64 Why is gradle using a differnt JDK while running from xCode?
If I add the following to gradle.properties.kts
#org.gradle.java.home=/Applications/Android\ <http://Studio.app/Contents/jbr/Contents/Home|Studio.app/Contents/jbr/Contents/Home>
its working from xCode. Unfortunately this is a hardcoded path and it will not be the same for every other developer.
l

Landry Norris

04/19/2023, 1:57 PM
You need to set your system jvm to the right version. It's best to not do it in gradle.properties. It works in AS, since AS uses its own jvm.
j

Jan

04/19/2023, 1:59 PM
And how do I set my system jvm to the right version? I thought exporting my JAVA_HOME via .zshrc like this "JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home" would help but didn't. What helped was to download&install java via https://www.java.com/en/download/
prio the fresh install of java I deinstalled the amazon-coretto-11 sdk via https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/macos-install.html
l

Landry Norris

04/19/2023, 2:03 PM
Is this macos? If so, there's /usr/bin/java_home or something like that.
j

Jan

04/19/2023, 2:03 PM
yes, macos
after deinstallation of amazon-coretto no java runtime was found at all during build of app via xcode
l

Landry Norris

04/19/2023, 2:06 PM
Use the java_home executable. It was either in /usr/bin or /usr/lib. It can detect and choose java versions.
Google will know the flags. I don't remember them off the top of my head.
j

Jan

04/19/2023, 2:13 PM
I do not understand completely. On MacOs I open a terminal/shell. When I enter "which java" it displays "/usr/bin/java". "java -v" then displays:
openjdk version "17.0.6" 2023-01-17
OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
OpenJDK 64-Bit Server VM (build 17.0.6+0-17.0.6b802.4-9586694, mixed mode)
After deinstall of amazon-coretto-jdk 11. The shell command "/usr/libexec/java_home -V" did not display anything. After I installed Java again from java.com the shell command now displays:
Matching Java Virtual Machines (1):
    1.8.371.11 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
After I installed it, XCode was able to build my iosApp again. So I don't understand whats the difference between these two?
l

Landry Norris

04/19/2023, 2:15 PM
/usr/bin/java is just a symlink. It points to the actual selected jvm. Install another jvm (I use homebrew for this), then select it with java_home
j

Jan

04/19/2023, 2:22 PM
but why does "/usr/libexec/java_home -V" only lists one jdk? I would expect that also the "openjdk version 17.0.6" should be listed
l

Landry Norris

04/19/2023, 2:24 PM
It may not be installed in the right place. It only checks a specific JavaVirtualMachines folder.
j

Jan

04/19/2023, 2:25 PM
ok, thanks for your help!
ok, I finally found a solution. It seems that I have to add my JAVA_HOME path to xCode, see https://twitter.com/creativedrewy/status/1648768542400192512?s=20