Xcode 12 Beta - Cannot find simulator runtime
This command can fix the issue:
sudo xcrun simctl shutdown all && sudo xcrun simctl erase all
And I found it here: https://developer.apple.com/forums/thread/653807
I have a similar problem building with Xcode 12 beta on Jenkins. When I run xcrun simctl list in Terminal with jenkins user, I see
== Runtimes ==
iOS 14.0 (14.0 - 18A5351d) - com.apple.CoreSimulator.SimRuntime.iOS-14-0
tvOS 14.0 (14.0 - 18J5364d) - com.apple.CoreSimulator.SimRuntime.tvOS-14-0
watchOS 7.0 (7.0 - 18R5361c) - com.apple.CoreSimulator.SimRuntime.watchOS-7-0
But if I put the same simctl command to be executed by a Jenkins job, the result is
== Runtimes ==
iOS 14.0 (14.0 - 18A5351d) - com.apple.CoreSimulator.SimRuntime.iOS-14-0 (unavailable, failed to open liblaunch_sim.dylib)
tvOS 14.0 (14.0 - 18J5364d) - com.apple.CoreSimulator.SimRuntime.tvOS-14-0 (unavailable, failed to open liblaunch_sim.dylib)
watchOS 7.0 (7.0 - 18R5361c) - com.apple.CoreSimulator.SimRuntime.watchOS-7-0 (unavailable, failed to open liblaunch_sim.dylib)
Although I could not find a solution, I found a workaround. If I stop Jenkins from running as a launch daemon and start it manually from the Terminal, then Xcode beta builds run fine.
# Stop Jenkins
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
# Impersonate jenkins user
sudo su - jenkins
# Tell Jenkins where its home dir is located
export JENKINS_HOME=/Users/Shared/Jenkins/Home
# Start Jenkins instance
/Library/Application\ Support/Jenkins/jenkins-runner.sh
All of the above paths are the default ones. If yours happen to be different, you may find the correct values in the file /Library/LaunchDaemons/org.jenkins-ci.plist
I am seeing this issue on Xcode 12.1 using the default install of Jenkins. None of these solutions work, and the "manual run of the sh script" results in Jenkins not even being able to load at all.
I am using a build command against a device (not a simulator) that looks like this:
/usr/bin/xcodebuild -scheme MyApp -workspace MyApp.xcworkspace -configuration Debug clean build DEVELOPMENT_TEAM=XXXXXXXXXX -allowProvisioningUpdates test -destination platform=iOS,id=theIDofADeviceNotASimulator
This command runs fine when I run it from the command prompt of my regular admin console user, but not from Jenkins.
Jenkins is installed normally under its own /users/Shared/Jenkins account.
Also, I see that in the Xcode 12.2 release notes (I am on 12.1) there is still a "known issue" that says Simulators may not be available when running command-line tools like simctl or xcodebuild from a non-root LaunchDaemon, or when launching as a different user from the current user (for example, with sudo or launchctl). (62188195) - https://developer.apple.com/documentation/xcode-release-notes/xcode-12_2-beta-release-notes
The issue seems to exist on the devices as well as the simulators.
UPDATE The solution is to reinstall Jenkins using homebrew under your regular user, have them auto-login, then use a LaunchAgent attached to that user to start jenkins when your user logs in.
Jenkins no longer supports being installed using the "jenkins user" and running as a LaunchDaemon, and neither does Xcode.