unity-azure-pipelines-tasks
unity-azure-pipelines-tasks copied to clipboard
Building iOS on MacOS MS-hosted machine
We're trying to build our Unity iOS app, but are running into an issue. We are using the UnitySetup task, which works great on a Windows MS-hosted machine. However, on MacOS it keeps complaining about not finding the Unity Hub executable.
After digging into the code, we found the following couple of lines:
// Setup and read inputs.
let unityHubExecutablePath = tl.getPathInput(customUnityHubPathInputVariableName);
if (!unityHubExecutablePath) {
// TODO: Add default paths for macOS / Linux.
unityHubExecutablePath = 'C:\\Program Files\\Unity Hub\\Unity Hub.exe';
}
We tried setting customUnityHubPath
to /Applications/Unity Hub.app
as this is the default location for Unity Hub on MacOS. But the pipeline fails: "Unable to locate executable file". If we understand correctly, the UnitySetup task expects Unity Hub to be installed on the machine and it's not installed on the MacOS images of Microsoft.
Is there a way (task) to download and install Unity Hub via a seperate task? We've looked into the unitysetup.powershell
module, but this only lets you install the Unity Editor.
Thank you in advance.
- task: PowerShell@2
displayName: 'Install Unity Hub'
inputs:
targetType: 'inline'
script: |
# Define the Unity Hub download URL for macOS
$unityHubUrl = "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.dmg"
# Define the default Applications directory
$applicationsDir = "/Applications"
# Download Unity Hub
Invoke-WebRequest -Uri $unityHubUrl -OutFile "$PSScriptRoot/UnityHubSetup.dmg"
# Mount the DMG file using hdiutil
hdiutil attach "$PSScriptRoot/UnityHubSetup.dmg" -nobrowse -mountpoint "$PSScriptRoot/MountedImage"
# Copy Unity Hub to the default Applications directory
Copy-Item -Path "$PSScriptRoot/MountedImage/Unity Hub.app" -Destination $applicationsDir -Recurse
chmod +x "$applicationsDir/Unity Hub.app/Contents/MacOS/Unity Hub"
# Unmount the DMG file
hdiutil detach "$PSScriptRoot/MountedImage"
# Print the installation directory
Write-Host "Unity Hub installed to: $applicationsDir/Unity Hub.app"
- task: UnitySetupTask@1
inputs:
versionSelectionMode: 'project'
installIOSModule: true
customUnityHubPath: /Applications/Unity Hub.app/Contents/MacOS/Unity Hub
I used this code snippet to download and setup Unity hub on a MacOS agent. I am not sure if there is any other better way to do this but this works