Search code examples
iosswiftrealmcarthagexcode10.1

Carthage update failure saying "Could not find any available simulators for iOS" - Xcode 10.1, macOS Mojave (10.14.2)


I am trying to install Realm to my project using Carthage. It used to work before but after switching to new MacBook Pro (15-inch, 2018, TouchBar) I am getting the following error,

carthage update --no-use-binaries --platform iOS
*** Fetching realm-cocoa
*** Checking out realm-cocoa at "v3.13.0"
*** xcodebuild output can be found in /var/folders/m4/1z0tvn6d67q2rqwcjvndy80m0000gn/T/carthage-xcodebuild.2vfx4v.log
*** Building scheme "Realm" in Realm.xcworkspace
Could not find any available simulators for iOS

I have tried uninstalling & reinstalling Carthage (0.31.2) and followed the steps given in these answers,

Stack Overflow Question

Carthage Git Issue

Carthage Fix and Release

xcrun simctl list devices --json

     {
        "availability" : "(available)",
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPad Pro",
        "udid" : "94790E33-EA0A-40B4-BA0A-19CC8D976A6F",
        "availabilityError" : ""
      }

Debug Carthage

(lldb) po devices[latestOSName]?.first { $0.isAvailable }
▿ Optional<Simulator>
  ▿ some : Simulator
    - isAvailable : true
    - name : "iPhone 5s"
    - udid : 87A9C887-034C-44A8-8F30-C90AF9ACCBCC

(lldb) po sdk.platform
XCDBLD.Platform.iOS

(lldb) po sdk.platform.rawValue
"iOS"

Looks like this issue still exists. Is there a way I could fix this to work on latest Xcode version?


Solution

  • Perhaps some checks you can make to narrow it down a little bit:

    Carthage version

    carthage version
    

    should output

    0.31.2
    

    Multiple Xcode installed

    xcode-select -p
    

    should give

    /Applications/Xcode.app/Contents/Developer
    

    for a standard installation.

    Simulator

    xcrun simctl list devices --json 
    

    That should output a list like:

    {
      "devices" : {
        "iOS 12.1" : [
          {
            "availability" : "(available)",
            "state" : "Shutdown",
            "isAvailable" : true,
            "name" : "iPhone 5s",
            "udid" : "1A6959A0-C10F-474B-96C5-7E8955FBDD80",
            "availabilityError" : ""
          },
      ...
    

    If there are no simulators add one using Xcode <Window/Devices and Simulators>.

    If there are entries please check if there is a 'isAvailable' entry with true as value:

    "isAvailable" : true,
    

    If not, check Xcode installation.

    Remove Caches

    One could als try to

    • quit Xcode
    • remove caches for Carthage and Xcode derived data folder

    As always when using rm -rf you have to be careful:

    rm -rf ~/Library/Caches/org.carthage.CarthageKit 
    rm -rf <your project folder>/Carthage
    xcrun simctl delete unavailable
    

    Then try again:

    carthage update --no-use-binaries --platform iOS
    

    Debug Carthage

    The nice thing about Carthage is that it is open source and even written in Swift.

    So to debug it we can:

    • quit Xcode
    • create a folder in Terminal and cd to the folder

    Then:

    git clone https://github.com/Carthage/Carthage.git
    cd Carthage
    git checkout 0.31.2
    make bootstrap
    open Carthage.xcworkspace
    

    Afterwards we need to enter command line arguments. To do so:

    • in Xcode use <Product/Scheme/Edit Scheme...>
    • on the left choose 'Run/Debug'
    • on the right choose tab 'Arguments'
    • change the 'Arguments Passed on Launch' to update --no-use-binaries --platform iOS

    Arguments

    • switch to the tab 'Options'
    • enter as `Working Directory' the path where the Cartfile resides

    Workding Directory

    Finally:

    • open Carthage/Source/CarthageKit/Simulator.swift
    • set breakpoints in the method selectAvailableSimulator

    Then you can debug what's going wrong.

    If everything is fine it would look like this:

    Debug Session

    If no error occurred when run from Xcode then let it run in Xcode completely without breakpoint and giving it some time to do the compile.

    If carthage update is successful from Xcode project then uninstall your current carthage installation as described here.

    How to uninstall Carthage from OS X?

    Then in Terminal go to the Carthage project folder where the Makefile resides and type:

    'make install'
    

    Afterwards you can try it from the command line again. It should work!