Unable to find application named 'Simulator'?

This is the run:

The line

open -a 'Simulator' --args -CurrentDeviceUDID $IOS_SIM_UDID

seems to output

Unable to find application named 'Simulator'

.

Is there any way to start the iOS Simulator? It is clearly listed in https://github.com/actions/virtual-environments/blob/40caaf3e2c11a9e4289482cce72e14ed97fa64fe/images/macos/macos-10.15-Readme.md#installed-simulators but I cannot find any way to use it.

Hi @happypig375,

According to the error message:
Unable to find application named 'Simulator'
I guess there is some settings missing for Simulator which points to the application path.

I run xcrun simctl list , the ID for iPhone 11 device iOS 13.5 is
67864C3A-1C15-48B9-96E5-EA9B279F2253.

To start the iOS simulator, you could try

xcrun simctl boot $IOS_SIM_UDID

According to https://stackoverflow.com/a/35821607/5429648
, that is not a full boot and some services (including those provided by the system app, like install or launch) are unavailable in this mode.

New run with correct UDID, error still persists. https://github.com/verybadcat/CSharpMath/runs/779554691?check_suite_focus=true

@yanjingzhu Is there any way to solve this?

I was trying hard to find a way to resolve your issue. But I met another issue .

Firstly, I found that the UID has changed today. There is a method to get uid of a simulator:

get_uid() {
  echo $( xcrun simctl list | grep -w $SIMULATOR_NAME | awk 'match($0, /\(([-0-9A-F]+)\)/) { print substr( $0, RSTART + 1, RLENGTH - 2 )}' )
}

And I tried to change Simulator to the exact path

xcrun simctl boot $IOS_SIM_UDID
open -a '/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator' --args -CurrentDeviceUDID $IOS_SIM_UDID

The scripts stuck at

   echo "Installing app at path $APP_PATH"
   xcrun simctl install booted $APP_PATH


As I am not familiar with ios, could you please check whether this script could run successfully in your local machine?

1 Like

Thank you! :heart: It now matches my local output.
The local script is:



#!/bin/bash
        nuget restore CSharpMath.sln
        msbuild CSharpMath.Ios.Tests
        export IOS_SIM_NAME='iPhone 11' # https://github.com/actions/virtual-environments/blob/fab29f60777e2532bfaa6578efdaca0f6dc05210/images/macos/macos-10.15-Readme.md#installed-simulators
        export BUNDLE_IDENTIFIER=CSharpMath.Ios.Unit-Tests # Located inside CSharpMath.Ios.Tests Info.plist file
        export APP_PATH=CSharpMath.Ios.Tests/bin/iPhoneSimulator/Debug/CSharpMath.Ios.Tests.app


        # run_ios_sim builds and runs an iOS app on the simulator
        #
        # It is designed to replicate the behavior of "Run" in Xcode and assumes basic
        # xcodebuild usage.
        # 
        # USAGE:
        # export IOS_SIM_UDID=342F9A20-DF48-41A9-BE60-C6B35F47E97F; \
        # export BUNDLE_IDENTIFIER=a.Some; \
        # export APP_PATH=$PWD/Build/Debug-iphonesimulator/$APP_NAME.app \
        # /path/to/run_ios_sim.sh 
        #
        # Note that the UDID must match a device where runtime is installed See
        # available devices with "simctl list"
        #
        # Additionally, it supports the ability to wait and attach LLDB in a similar
        # fashion that Xcode does.
        # export DEBUGGER_ENABLED=1|0
        #
        # Tested on Xcode 8.3.1 a few times
        # Author: Jerry Marino - @jerrymarino

        APP_NAME=`echo ""${APP_PATH##*/}"" | cut -d'.' -f1`

        echo "Running sim for $APP_NAME - $BUNDLE_IDENTIFIER"

        IOS_SIM_UDID=`xcrun simctl list | grep -w $SIMULATOR_NAME | awk 'match($0, /\(([-0-9A-F]+)\)/) { print substr( $0, RSTART + 1, RLENGTH - 2 )}'`

        SIMULATOR_PATH='/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator'


        # If the booted simulator does not match, then we need to restart it. Expect an
        # output list of the form
        # "Phone: iPhone 7 Plus (342F9A20-DF48-41A9-BE60-C6B35F47E97F) (Booted)"
        BOOTED_UDID=`xcrun simctl list | grep Booted | perl -pe 's/(.*\()(.*)\)+ (.*)/\2/' | sed -n 1p`
        if [[ $BOOTED_UDID != $IOS_SIM_UDID ]]; then
          killall $SIMULATOR_PATH
        else
          # FIXME: We don't need to do this for all cases and
          # it is slow
          killall $SIMULATOR_PATH
        fi

        # Open the simulator
        open -a $SIMULATOR_PATH --args -CurrentDeviceUDID $IOS_SIM_UDID

        # Wait until there is a device booted

        function booted_sim_ct() {
          echo `xcrun simctl list | grep Booted | wc -l | sed -e 's/ //g'`
        }

        while [ `booted_sim_ct` -lt 1 ]
        do
          sleep 1
        done

        echo "Installing app at path $APP_PATH"
        xcrun simctl install booted $APP_PATH

        if [[ $DEBUGGER_ENABLED == "1" ]]; then
          LAUNCH_DEBUGGER_ENABLED_FLAG=--wait-for-debugger
          USE_CONSOLE_FLAG=""
        else
          USE_CONSOLE_FLAG=--console
          LAUNCH_DEBUGGER_ENABLED_FLAG=""
        fi

        LOG_FILE=/tmp/run_ios_sim.log
        echo "Starting Sim for $APP_PATH" > $LOG_FILE

        # Launch the app program into the booted sim
        # - Pipe the output to a log file
        # - Run in the background
        `xcrun simctl launch $LAUNCH_DEBUGGER_ENABLED_FLAG $USE_CONSOLE_FLAG booted $BUNDLE_IDENTIFIER 2>&1 >> $LOG_FILE` &

        LAUNCH_SHELL_PID=$!

        function newest_related_process() {
          echo `ps aux | grep $APP_NAME.app/$APP_NAME | grep -v -e "*.grep" | sort -k 4nr,4  | awk '{ print ( $2 > '$LAUNCH_SHELL_PID' ) ? $2 : "" }' | grep -v -e '^$' | head -1`
        }

        # Wait for the process to launch. We need to get the PID of the launched App
        _Z=`newest_related_process`
        _X=0
        while [[ "$_Z" != "$_X" ]]
        do
          sleep 1
          _Z=$_X
          _X=`newest_related_process`
          echo "waiting for process.."
        done

        APP_PID=$_X

        if [[ $DEBUGGER_ENABLED == "1" ]]; then
          # Manually startup LLDB.
          echo "$APP_NAME running at pid $APP_PID, waiting for lldb.."
          lldb -p $APP_PID
        else
          # If not debugging read the log file
          # when the log closes, the app will terminate
          echo "$APP_NAME running at pid $APP_PID"
          tail -f $LOG_FILE
        fi

On local testing, the app has successfully launched but the script seems to not able to detect it. Some more Googling will be required.

If I add add two echoes to the problematic loop,

        while [[ "$_Z" != "$_X" ]]
        do
          sleep 1
          _Z=$_X
          _X=`newest_related_process`
          echo Z is $_Z
          echo X is $_X
          echo "waiting for process.."
        done

, the output becomes

Z is 0
X is 2301
waiting for process..
Z is 2301
X is 2311
waiting for process..
Z is 2311
X is 2321
waiting for process..
Z is 2321
X is 2331
waiting for process..
Z is 2331
X is 2341
waiting for process..
Z is 2341
X is 2351
waiting for process..
Z is 2351
X is 2361
waiting for process..
Z is 2361
X is 2371
waiting for process..
Z is 2371
X is 2381
waiting for process..
Z is 2381
X is 2391
waiting for process..

I have replaced

ps aux | grep $APP_NAME.app/$APP_NAME | grep -v -e "*.grep" | sort -k 4nr,4  | awk '{ print ( $2 > '$LAUNCH_SHELL_PID' ) ? $2 : "" }' | grep -v -e '^$' | head -1

with

pgrep $APP_NAME -P $LAUNCH_SHELL_PID | head -1

and it seems to work correctly.

I am very glad to hear that you have resolved your issue. If you meet any other issue when using GitHub Actions, welcome to our community again. :smiley:

1 Like

Thanks @yanjingzhu! The final form of the workflow file can be seen in https://github.com/verybadcat/CSharpMath/pull/133/files#diff-bb44396ad1769acfefe20015d1f4a095 where an app file is loaded into the simulator and the app logs are extracted for checking for test failures.