kuler90 / setup-unity

GitHub Action to download and install Unity on Ubuntu, macOS or Windows. Based on Unity Hub
MIT License
37 stars 33 forks source link

Android build fails with UnityException: JDK not found on Windows #17

Closed camnewnham closed 1 year ago

camnewnham commented 1 year ago

Hi, thanks for making this action public. It's very helpful.

After using the action kuler90/setup-unity@v1 with Android on a windows-latest (windows-2022) image on github actions I get the following in the Unity build log (and the build fails):

DisplayProgressbar: Checking prerequisites
Android PostProcess task "Checking prerequisites" took 4.386 ms
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
UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[], Boolean)
UnityEditor.BuildPipeline:BuildPlayerInternal(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[])
UnityEditor.BuildPipeline:BuildPlayer(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[])
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)

The setup-unity log looks normal:

94.[69](https://github.com/Fologram/xr.unity/actions/runs/5664664631/job/15348281824#step:4:70)% of Unity editor "2022.3.4f1" was downloaded 
97.83% of Unity editor "2022.3.4f1" was downloaded 
Unity Editor "2022.3.4f1" successfully downloaded.
Installing Unity Editor "2022.3.4f1"Installation done
"C:/Program Files/Unity Hub/Unity Hub.exe" -- --headless editors --installed

2022.3.4f1 , installed at C:\Program Files\Unity\Hub\Editor\2022.3.4f1\Editor\Unity.exe

"C:/Program Files/Unity Hub/Unity Hub.exe" -- --headless install-modules --version 2022.3.4f1 --module android --childModules

Adding module android-sdk-platform-tools as dependency of android-sdk-ndk-tools.

Adding module android-sdk-build-tools as dependency of android-sdk-ndk-tools.

Adding module android-sdk-platforms as dependency of android-sdk-ndk-tools.

Adding module android-ndk as dependency of android-sdk-ndk-tools.

Adding module android-sdk-platform-tools as dependency of android-sdk-ndk-tools.

Adding module android-sdk-build-tools as dependency of android-sdk-ndk-tools.

Adding module android-sdk-platforms as dependency of android-sdk-ndk-tools.

Adding module android-ndk as dependency of android-sdk-ndk-tools.

Modules installed successfully.

Some discussions here that mention this was an issue (on ubuntu however...) in an older hub version when installing headless: https://github.com/game-ci/unity-builder/issues/489

camnewnham commented 1 year ago

I've worked around this by using powershell based on the js code from this repo

      - name: Install Unity
        id: install_unity
        run: |
          $match = [regex]::match((Get-Content -Path ProjectSettings\ProjectVersion.txt | Out-String), 'm_EditorVersionWithRevision: (?<version>[^\s]+) \((?<changeset>[^\)]+)\)')
          $unityVersion = $match.groups["version"].Value
          $unityChangeset = $match.groups["changeset"].Value

          curl --output installer.exe "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.exe"
          Invoke-Expression "& '.\installer.exe' /S | Out-Default"
          Invoke-Expression "& 'C:/Program Files/Unity Hub/Unity Hub.exe' -- --headless install --version $unityVersion --changeset $unityChangeset | Out-Default"
          Invoke-Expression "& 'C:/Program Files/Unity Hub/Unity Hub.exe' -- --headless install-modules --version $unityVersion --module $env:UNITY_MODULES --childModules | Out-Default"

          echo "UNITY_PATH=$("C:\Program Files\Unity\Hub\Editor\$unityVersion\Editor\Unity.exe")" >> $env:GITHUB_ENV