If you use sdkman like I do, you might need to tell Xcode where to find it if you run into " Unable to locate a Java Runtime" during a failed build of the iosApp in Xcode. You can do this by creating environment.plist
in ~/Library/LaunchAgents/
and pasting in this code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.startup</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>
launchctl setenv JAVA_HOME /Users/user/.sdkman/candidates/java/current/
</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Be sure to use your actual username in place of “user” above
courtesy of this post:
opened 03:34PM - 12 Feb 20 UTC
closed 04:49PM - 23 Mar 21 UTC
Taken from slack...
Sven Bendel Today at 9:25 AM
Hi, I've just started to … play around with the kampkit sample app on my Mac. Android works like a charm. However, on iOS I can't seem to build the app. I always get the dreaded "To use the “java” command-line tool you need to install a JDK." dialog. However, I have java and the JDK installed on my system, although not in the default location. I'm using sdkman to manage java versions, current version resides at /Users/ubuntudroid/.sdkman/candidates/java/current. I guess I somehow need to tell xcode to use that. JAVA_HOME environment variable is set to the abovementioned value, but xcode seems not to make use of it (I guess it only looks in the default . Any ideas?
25 replies
Marc Reichelt 1 hour ago
What’s your Java version?
Marc Reichelt 1 hour ago
java -version
Marc Reichelt 1 hour ago
KaMP Kit docs say ‘JVM 8’
Marc Reichelt 1 hour ago
if you get openjdk 1.8.0 you should be fine
Sven Bendel 1 hour ago
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)
Sven Bendel 1 hour ago
but I don't think it's being picked up at all by xcode
Marc Reichelt 1 hour ago
yep, definitely try a 1.8.0 openjdk
Sven Bendel 1 hour ago
kk, will try
Sven Bendel 1 hour ago
Now I have
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)
Sven Bendel 1 hour ago
Unfortunately I still get the popup. :disappointed:
Sven Bendel 42 minutes ago
I guess Xcode is trying to execute the gradle task :shared:syncFramework and then gradle (running in the xcode environment) does not find my java environment. :thinking_face:
Marc Reichelt 26 minutes ago
hmm, maybe it chooses the wrong java version
Marc Reichelt 26 minutes ago
when you set JAVA_HOME: did you logout & login your user on your Mac?
Marc Reichelt 25 minutes ago
that might do the trick (because then freshly started apps get the updated env variables)
Marc Reichelt 25 minutes ago
If you can, try to find out which java command Xcode runs
Marc Reichelt 25 minutes ago
which ‘java’ binary exactly
Marc Reichelt 24 minutes ago
it seems on your machine it finds a JRE java binary instead of the JDK one
Marc Reichelt 24 minutes ago
maybe there is the old java binary from Apple installed
Sven Bendel 24 minutes ago
thanks for your outstanding support on this matter :pray: - I'll restart my Mac (to be on the safe side) and see whether this resolves things. Then I'll try out the other things you've suggested.
Marc Reichelt 23 minutes ago
I usually fix these things by uninstalling all JREs and JDKs on my machine and just installing openjdk 1.8.0 with homebrew :wink:
Marc Reichelt 23 minutes ago
glad to help - hope it works :slightly_smiling_face:
Sven Bendel 23 minutes ago
haha, I feared that would be the answer :sweat_smile:
Sven Bendel 18 minutes ago
Hm, okay, restarting didn't work - trying your other recommendations now
Sven Bendel 3 minutes ago
Ha, I've managed to get things up and running by hardcoding JAVACMD in gradlew - it seems that xcode indeed launches the process without properly setting proper environment variables.
Sven Bendel 2 minutes ago
Trying to find a better solution for this while keeping on using sdkman. Will post my findings here if I am successful.
1 Like
Thank you for the heads up evanadwyer!
We’re going to look into this and add it on the next book revision :].