I have been trying the Unity Hub CLI recently on our CI/CD pipeline, but building for Android/Meta Quest 3, it won’t discover the Android JDK.
I installed it with the following command:
'C:/Program Files/Unity Hub/Unity Hub.exe' -- --headless install-modules --version 2022.3.53f1 -m uwp-il2cpp android --cm
. Unity is installed as expected, and the JDK/SDK/NDK files seems to be in the correct location. I have tried multiple different Unity versions.
If I build locally on my computer it creates an apk as expected, but on the build machine it returns the following exception:
DisplayProgressbar: Detect Java Development Kit (JDK)
UnityException: JDK not found
Java Development Kit (JDK) directory is not set or invalid. Please, fix it in Edit / Unity -> Preferences -> External Tools
Any ideas? Any way to set the JDK path from the command line? Thanks!
Hi, holomagnus. Could you provide your Editor.log? Some help on how to find the file can be found here.
I’m facing the same issue with Unity Version 2021.3.44.
On the same machine, building from the Editor works without problems and produces the expected apk.
But trying to run a command line build stops after some minutes with the following error:
[...]
13:49:59 Preloading 2 native plugins for Editor in 0.15 ms.
13:49:59 Asset Pipeline Refresh: Total: 0.226 seconds - Initiated by StopAssetImportingV2(NoUpdateAssetOptions)
13:49:59 DisplayProgressbar: Checking prerequisites
13:49:59 Android PostProcess task "Checking prerequisites" took 7,8286 ms
13:49:59 DisplayProgressbar: Detect Java Development Kit (JDK)
13:49:59 UnityException: JDK not found
13:49:59 Java Development Kit (JDK) directory is not set or invalid. Please, fix it in Edit / Unity -> Preferences -> External Tools
13:49:59 UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[], Boolean)
13:49:59 UnityEditor.BuildPipeline:BuildPlayerInternal(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[])
13:49:59 UnityEditor.BuildPipeline:BuildPlayer(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[])
13:49:59 UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
[...]
In case it’s relevant: we’re not triggering the build directly by a command line parameter but we’re running a C# script, which in turn starts the build after some pre-processing.
@JonasBaliutis If it helps I can provide the full build output. However, I’d rather do this via private message. Let me know if I should do so.
Is there a way to see and set the Editor preference for JDK path via command line? If that works it would be a decent workaround. Our build server is headless, so we can’t set it via GUI.
I sent a full build log in dm. @JonasBaliutis
Thanks for looking into this.
1 Like
One of the developers took a peek at your case and responded with this:
This is an issue with the Unity Hub, they need to either set the LTS version without a patch (it will get the last one available) by using -- --headless install --version 2022.3 -m uwp-il2cpp android --childModules
, or, if they want a specific patch, they need to also indicate the changeset (which they can find on the Unity Archive) by using -- --headless install --version 2022.3.53f1 --changeset "df4e529d20d3" -m uwp-il2cpp android --childModules
.
Hope this helps!
I tried this:
- Run uninstall.exe
- Remove some leftover folders
- Install with & ‘.\Unity Hub.exe’ – --headless install --version 2022.3.53f1 --changeset “df4e529d20d3” -m uwp-il2cpp android --childModules
- Run a build
Still fails with the same message
I’ll send the log on DM again.
Its is quite painful if we have to do the no-patch install. Not being able to choose the patch makes it hard to stay in sync with dev-machines.
Honestly I think this is an issue of the Editor, not of the Hub. In my case, I installed the Editor regularly via the Hub GUI, but still the CLI build (which does not use the Hub at all) afterwards fails.
If I open the Editor GUI and go to the preferences, there is a valid path to the JDK shown, and building via the Editor GUI works and produces a working result.
1 Like
I had a theory it might be that the exe is called from different working directories, but that works fine locally. I also tried a clean build (delete Library/obj/*proj/*csproj), but that also works fine locally.
In essence I’ve as closely as I can reproduced the exact scenario on the build server, but it still works locally.
I managed to solve the problem in our case. It turned out the system variable JAVA_HOME still pointed to the old editor version that was no longer installed. After changing it to the new location and restarting the server, the command line build worked again.
The error message “Java Development Kit (JDK) directory is not set or invalid. Please, fix it in Edit / Unity → Preferences → External Tools” was very misleading in this case, as it seems that the path set in the Unity editor is irrelevant when building on the command line.
This made no difference on my server. Locally the build works, but JAVA_HOME is not set.
Hi again, Andre-ba. Could you report this as a bug via the Bug Reporter (“Help → Report a Bug…” in the Unity Editor)? This will make it easier to follow and investigate the issue.
Also, I’ve sent your previous update to the developer who took a peek into your situation earlier, but they’re currently on holiday leave. So this will probably be looked into more closely only in January.