Xcode Simulator Close App

broken image


In this tutorial, you will learn how to build a simple iOS app. You'll do thefollowing:

Go to Window - Devices and Simulators. This will open a new window with all the devices you use in Xcode. At the top, tap on Simulators and you'll see a list on the left-side. From there, find the simulator you want to delete and Cntl - click (or right-click) and select Delete. If you want to test an app in the iOS emulator of Xcode and click on 'Run', the app automatically starts immediately in the simulator. Unfortunately, I have not found any possibility to close or exit this app in the simulator again to get access to the normal smartphone menu of the simulated iPhone mobile device.

  • Set up your environment
  • Set up a workspace
  • Create a BUILD file
  • Build and deploy the app

Set up your environment

To get started, install Bazel and Xcode, and get the sample project.

Install Bazel

Follow the installation instructions to install Bazel andits dependencies.

Install Xcode

Download and install Xcode.Xcode contains the compilers, SDKs, and other tools required by Bazel to buildApple applications.

Get the sample project

You also need to get the sample project for the tutorial from GitHub. The GitHubrepo has two branches: source-only and master. The source-only branchcontains the source files for the project only. You'll use the files in thisbranch in this tutorial. The master branch contains both the source filesand completed Bazel WORKSPACE and BUILD files. You can use the files in thisbranch to check your work when you've completed the tutorial steps.

Enter the following at the command line to get the files in the source-onlybranch:

The git clone command creates a directory named $HOME/examples/. Thisdirectory contains several sample projects for Bazel. The project files for thistutorial are in $HOME/examples/tutorial/ios-app.

Set up a workspace

X64

A workspace is a directory that contains thesource files for one or more software projects, as well as a WORKSPACE fileand BUILD files that contain the instructions that Bazel uses to buildthe software. The workspace may also contain symbolic links to outputdirectories.

A workspace directory can be located anywhere on your filesystem and is denotedby the presence of the WORKSPACE file at its root. In this tutorial, yourworkspace directory is $HOME/examples/tutorial/, which contains the sampleproject files you cloned from the GitHub repo in the previous step.

Note that Bazel itself doesn't impose any requirements for organizing sourcefiles in your workspace. The sample source files in this tutorial are organizedaccording to conventions for the target platform.

For your convenience, set the $WORKSPACE environment variable now to refer toyour workspace directory. At the command line, enter:

Create a WORKSPACE file

Every workspace must have a text file named WORKSPACE located in the top-levelworkspace directory. This file may be empty or it may contain referencesto external dependencies required to build thesoftware.

For now, you'll create an empty WORKSPACE file, which simply serves toidentify the workspace directory. In later steps, you'll update the file to addexternal dependency information.

Enter the following at the command line:

This creates and opens the empty WORKSPACE file.

Update the WORKSPACE file

To build applications for Apple devices, Bazel needs to pull the latestApple build rules from its GitHubrepository. To enable this, add the following git_repositoryrules to your WORKSPACE file:

NOTE: 'Always use the latest version of the build_apple rulesin the tag attribute. Make sure to check the latest dependencies required inrules_apple's project.'

NOTE: You must set the value of the name attribute in thegit_repository rule to build_bazel_rules_apple or the build will fail.

Review the source files

Take a look at the source files for the app located in$WORKSPACE/ios-app/UrlGet. Again, you're just looking at these files now tobecome familiar with the structure of the app. You don't have to edit any of thesource files to complete this tutorial.

Create a BUILD file

At a command-line prompt, open a new BUILD file for editing:

Add the rule load statement

To build iOS targets, Bazel needs to load build rules from its GitHub repositorywhenever the build runs. To make these rules available to your project, add thefollowing load statement to the beginning of your BUILD file:

We only need to load the ios_application rule because the objc_library ruleis built into the Bazel package.

Add an objc_library rule

Bazel provides several build rules that you can use to build an app for theiOS platform. For this tutorial, you'll first use theobjc_library rule to tell Bazelhow to build a static library from the app source code and Xib files. Thenyou'll use theios_applicationrule to tell it how to build the application binary and the .ipa bundle.

NOTE: This tutorial presents a minimal use case of the Objective-C rules inBazel. For example, you have to use the ios_application rule to buildmulti-architecture iOS apps.

Add the following to your BUILD file:

Note the name of the rule, UrlGetClasses.

Add an ios_application rule

Theios_applicationrule builds the application binary and creates the .ipa bundle file.

Add the following to your BUILD file:

NOTE: Please update the minimum_os_version attribute to the minimumversion of iOS that you plan to support.

Note how the deps attribute references the output of the UrlGetClasses ruleyou added to the BUILD file above.

Now, save and close the file. You can compare your BUILD file to thecompleted examplein the master branch of the GitHub repo.

Build and deploy the app

You are now ready to build your app and deploy it to a simulator and onto aniOS device.

NOTE: The app launches standalone but requires a backend server in order toproduce output. See the README file in the sample project directory to find outhow to build the backend server.

Build the app for the simulator

Make sure that your current working directory is inside your Bazel workspace:

Now, enter the following to build the sample app:

Bazel launches and builds the sample app. During the build process, itsoutput will appear similar to the following:

Xcode 12 X64 Simulator

Find the build outputs

The .ipa file and other outputs are located in the$WORKSPACE/bazel-bin/ios-app directory.

Run and debug the app in the simulator

You can now run the app from Xcode using the iOS Simulator. First, generate an Xcode project using Tulsi.

Then, open the project in Xcode, choose an iOS Simulator as the runtime scheme,and click Run.

Note: If you modify any project files in Xcode (for example, if you add orremove a file, or add or change a dependency), you must rebuild the app usingBazel, re-generate the Xcode project in Tulsi, and then re-open the project inXcode.

Build the app for a device

To build your app so that it installs and launches on an iOS device, Bazel needsthe appropriate provisioning profile for that device model. Do the following:

  1. Go to your Apple Developer Account anddownload the appropriate provisioning profile for your device. SeeApple's documentationfor more information.

  2. Move your profile into $WORKSPACE.

  3. (Optional) Add your profile to your .gitignore file.

  4. Add the following line to the ios_application target in your BUILD file:

    NOTE: Ensure the profile is correct so that the app can be installed ona device.

Now build the app for your device:

This builds the app as a fat binary. To build for a specific devicearchitecture, designate it in the build options.

To build for a specific Xcode version, use the --xcode_version option. Tobuild for a specific SDK version, use the --ios_sdk_version option. The--xcode_version option is sufficient in most scenarios.

To specify a minimum required iOS version, add the minimum_os_versionparameter to the ios_application build rule in your BUILD file.

You can also use Tulsi tobuild your app using a GUI rather than the command line.

Xcode Simulator For Windows

Install the app on a device

The easiest way to install the app on the device is to launch Xcode and use theWindows > Devices command. Select your plugged-in device from the list on theleft, then add the app by clicking the Add (plus sign) button under'Installed Apps' and selecting the .ipa file that you built.

If your app fails to install on your device, ensure that you are specifying thecorrect provisioning profile in your BUILD file (step 4 in the previoussection).

If your app fails to launch, make sure that your device is part of yourprovisioning profile. The View Device Logs button on the Devices screen inXcode may provide other information as to what has gone wrong.

Review your work

In this tutorial, you used Bazel to build an iOS app. To accomplish that, you:

  • Set up your environment by installing Bazel and Xcode, and downloading thesample project
  • Set up a Bazel workspace that contained the source codefor the app and a WORKSPACE file that identifies the top level of theworkspace directory
  • Updated the WORKSPACE file to contain references to the requiredexternal dependencies
  • Created a BUILD file
  • Ran Bazel to build the app for the simulator and an iOS device
  • Ran the app in the simulator and on an iOS device

The built app is located in the $WORKSPACE/bazel-bin directory.

Completed WORKSPACE and BUILD files for this tutorial are located in themaster branchof the GitHub repo. You can compare your work to the completed files foradditional help or troubleshooting.

I'm running Xcode 4.3.1 iOS-Simulator which originally only supports iOS 5.1.

I need to test my code with iOS 4.3, so I used Xcode's 'Install' feature to install it as described in 'Installing Xcode with iOS 4.3 device simulator?'

Now I'm finished with testing but cannot find a way to uninstall the 4.3 portions ('iPhone 4.3 Simulator' and 'iPad 4.3 Simulator'). I want to reduce the clutter in the Scheme menu.

No one on Apple's Xcode listserv knew the answer!

EDIT: note that much has changed since Xcode 4.3, so suggest anyone reading this look at all the answers. The newest ones such as Steve Moser's may be of more use to you!

EDIT 10/2017: Posted on Twitter by Julio Carrettoni‏

Did not try it myself…[Also, I just saw Russ Bishop mentioned this in a comment below already…]

Answers:

Did you tried to just delete the 4.3 SDK from within the Xcode Package?

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs

please also delete the corresponding .dmg file in

~/Library/Caches/com.apple.dt.Xcode/Downloads

to prevent Xcode from re-installing the same package again. Adobe photoshop for mac cost.

for XCode >= 6 see @praveen-matanam ‘s answer

Answers:

In Xcode 6+ you can simply go to Menu > Window > Devices > Simulators and delete a simulator you don't need.

Answers:

In Xcode 6 and above, you can find and delete the simulators from the path /Library/Developer/CoreSimulator/Profiles/Runtimes. Restart Xcode in order to take effect (may not be needed).

Answers:

Run this command in terminal to remove simulators that can't be accessed from the current version of Xcode (8+?) in use on your machine.

xcrun simctl delete unavailable

Answers:

Xcode 4.6 will prompt you to reinstall any older versions of the iOS Simulator if you just delete the SDK. To avoid that, you must also delete the Xcode cache. Then you won't be forced to reinstall the older SDK on launch.

To remove the iOS 5.0 simulator, delete these and then restart Xcode:

  1. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/PhoneSimulator5.0.sdk
  2. ~/Library/Caches/com.apple.dt.Xcode

For example, after doing a clean install of Xcode, I installed the iOS 5.0 simulator from Xcode preferences. Later, I decided that 5.1 was enough but couldn't remove the 5.0 version. Xcode kept forcing me to reinstall it on launch. After removing both the cache file and the SDK, it no longer asked.

Answers:

September 2017, Xcode 9

You will find them here:

To delete devices go here:

Much easier to delete them use Xcode:
Xcode->Window->Devices and Simulators

Helping Xcode 'forget' about runtimes and prevent from re-installing them – delete .dmg file(s) here:

I hope it will help someone ?

Answers:

In addition to @childno.de answer, your Mac directory

/private/var/db/receipts/

may still contains obsolete iPhoneSimulatorSDK .bom and .plist files like this:

/private/var/db/receipts/com.apple.pkg.iPhoneSimulatorSDK8_4.bom
/private/var/db/receipts/com.apple.pkg.iPhoneSimulatorSDK8_4.plist

These could make your Downloads tab of Xcode's preferences show a tick () for that obsolete simulator version.

To purge the unwanted simulators, you can do a search using this bash command from your Mac terminal:

Xcode Simulator Using All My Memory

sudo find / -name '*PhoneSimulator*'

Then go to corresponding directories to manually delete unwanted SimulatorSDKs

Answers:
Xcode

A workspace is a directory that contains thesource files for one or more software projects, as well as a WORKSPACE fileand BUILD files that contain the instructions that Bazel uses to buildthe software. The workspace may also contain symbolic links to outputdirectories.

A workspace directory can be located anywhere on your filesystem and is denotedby the presence of the WORKSPACE file at its root. In this tutorial, yourworkspace directory is $HOME/examples/tutorial/, which contains the sampleproject files you cloned from the GitHub repo in the previous step.

Note that Bazel itself doesn't impose any requirements for organizing sourcefiles in your workspace. The sample source files in this tutorial are organizedaccording to conventions for the target platform.

For your convenience, set the $WORKSPACE environment variable now to refer toyour workspace directory. At the command line, enter:

Create a WORKSPACE file

Every workspace must have a text file named WORKSPACE located in the top-levelworkspace directory. This file may be empty or it may contain referencesto external dependencies required to build thesoftware.

For now, you'll create an empty WORKSPACE file, which simply serves toidentify the workspace directory. In later steps, you'll update the file to addexternal dependency information.

Enter the following at the command line:

This creates and opens the empty WORKSPACE file.

Update the WORKSPACE file

To build applications for Apple devices, Bazel needs to pull the latestApple build rules from its GitHubrepository. To enable this, add the following git_repositoryrules to your WORKSPACE file:

NOTE: 'Always use the latest version of the build_apple rulesin the tag attribute. Make sure to check the latest dependencies required inrules_apple's project.'

NOTE: You must set the value of the name attribute in thegit_repository rule to build_bazel_rules_apple or the build will fail.

Review the source files

Take a look at the source files for the app located in$WORKSPACE/ios-app/UrlGet. Again, you're just looking at these files now tobecome familiar with the structure of the app. You don't have to edit any of thesource files to complete this tutorial.

Create a BUILD file

At a command-line prompt, open a new BUILD file for editing:

Add the rule load statement

To build iOS targets, Bazel needs to load build rules from its GitHub repositorywhenever the build runs. To make these rules available to your project, add thefollowing load statement to the beginning of your BUILD file:

We only need to load the ios_application rule because the objc_library ruleis built into the Bazel package.

Add an objc_library rule

Bazel provides several build rules that you can use to build an app for theiOS platform. For this tutorial, you'll first use theobjc_library rule to tell Bazelhow to build a static library from the app source code and Xib files. Thenyou'll use theios_applicationrule to tell it how to build the application binary and the .ipa bundle.

NOTE: This tutorial presents a minimal use case of the Objective-C rules inBazel. For example, you have to use the ios_application rule to buildmulti-architecture iOS apps.

Add the following to your BUILD file:

Note the name of the rule, UrlGetClasses.

Add an ios_application rule

Theios_applicationrule builds the application binary and creates the .ipa bundle file.

Add the following to your BUILD file:

NOTE: Please update the minimum_os_version attribute to the minimumversion of iOS that you plan to support.

Note how the deps attribute references the output of the UrlGetClasses ruleyou added to the BUILD file above.

Now, save and close the file. You can compare your BUILD file to thecompleted examplein the master branch of the GitHub repo.

Build and deploy the app

You are now ready to build your app and deploy it to a simulator and onto aniOS device.

NOTE: The app launches standalone but requires a backend server in order toproduce output. See the README file in the sample project directory to find outhow to build the backend server.

Build the app for the simulator

Make sure that your current working directory is inside your Bazel workspace:

Now, enter the following to build the sample app:

Bazel launches and builds the sample app. During the build process, itsoutput will appear similar to the following:

Xcode 12 X64 Simulator

Find the build outputs

The .ipa file and other outputs are located in the$WORKSPACE/bazel-bin/ios-app directory.

Run and debug the app in the simulator

You can now run the app from Xcode using the iOS Simulator. First, generate an Xcode project using Tulsi.

Then, open the project in Xcode, choose an iOS Simulator as the runtime scheme,and click Run.

Note: If you modify any project files in Xcode (for example, if you add orremove a file, or add or change a dependency), you must rebuild the app usingBazel, re-generate the Xcode project in Tulsi, and then re-open the project inXcode.

Build the app for a device

To build your app so that it installs and launches on an iOS device, Bazel needsthe appropriate provisioning profile for that device model. Do the following:

  1. Go to your Apple Developer Account anddownload the appropriate provisioning profile for your device. SeeApple's documentationfor more information.

  2. Move your profile into $WORKSPACE.

  3. (Optional) Add your profile to your .gitignore file.

  4. Add the following line to the ios_application target in your BUILD file:

    NOTE: Ensure the profile is correct so that the app can be installed ona device.

Now build the app for your device:

This builds the app as a fat binary. To build for a specific devicearchitecture, designate it in the build options.

To build for a specific Xcode version, use the --xcode_version option. Tobuild for a specific SDK version, use the --ios_sdk_version option. The--xcode_version option is sufficient in most scenarios.

To specify a minimum required iOS version, add the minimum_os_versionparameter to the ios_application build rule in your BUILD file.

You can also use Tulsi tobuild your app using a GUI rather than the command line.

Xcode Simulator For Windows

Install the app on a device

The easiest way to install the app on the device is to launch Xcode and use theWindows > Devices command. Select your plugged-in device from the list on theleft, then add the app by clicking the Add (plus sign) button under'Installed Apps' and selecting the .ipa file that you built.

If your app fails to install on your device, ensure that you are specifying thecorrect provisioning profile in your BUILD file (step 4 in the previoussection).

If your app fails to launch, make sure that your device is part of yourprovisioning profile. The View Device Logs button on the Devices screen inXcode may provide other information as to what has gone wrong.

Review your work

In this tutorial, you used Bazel to build an iOS app. To accomplish that, you:

  • Set up your environment by installing Bazel and Xcode, and downloading thesample project
  • Set up a Bazel workspace that contained the source codefor the app and a WORKSPACE file that identifies the top level of theworkspace directory
  • Updated the WORKSPACE file to contain references to the requiredexternal dependencies
  • Created a BUILD file
  • Ran Bazel to build the app for the simulator and an iOS device
  • Ran the app in the simulator and on an iOS device

The built app is located in the $WORKSPACE/bazel-bin directory.

Completed WORKSPACE and BUILD files for this tutorial are located in themaster branchof the GitHub repo. You can compare your work to the completed files foradditional help or troubleshooting.

I'm running Xcode 4.3.1 iOS-Simulator which originally only supports iOS 5.1.

I need to test my code with iOS 4.3, so I used Xcode's 'Install' feature to install it as described in 'Installing Xcode with iOS 4.3 device simulator?'

Now I'm finished with testing but cannot find a way to uninstall the 4.3 portions ('iPhone 4.3 Simulator' and 'iPad 4.3 Simulator'). I want to reduce the clutter in the Scheme menu.

No one on Apple's Xcode listserv knew the answer!

EDIT: note that much has changed since Xcode 4.3, so suggest anyone reading this look at all the answers. The newest ones such as Steve Moser's may be of more use to you!

EDIT 10/2017: Posted on Twitter by Julio Carrettoni‏

Did not try it myself…[Also, I just saw Russ Bishop mentioned this in a comment below already…]

Answers:

Did you tried to just delete the 4.3 SDK from within the Xcode Package?

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs

please also delete the corresponding .dmg file in

~/Library/Caches/com.apple.dt.Xcode/Downloads

to prevent Xcode from re-installing the same package again. Adobe photoshop for mac cost.

for XCode >= 6 see @praveen-matanam ‘s answer

Answers:

In Xcode 6+ you can simply go to Menu > Window > Devices > Simulators and delete a simulator you don't need.

Answers:

In Xcode 6 and above, you can find and delete the simulators from the path /Library/Developer/CoreSimulator/Profiles/Runtimes. Restart Xcode in order to take effect (may not be needed).

Answers:

Run this command in terminal to remove simulators that can't be accessed from the current version of Xcode (8+?) in use on your machine.

xcrun simctl delete unavailable

Answers:

Xcode 4.6 will prompt you to reinstall any older versions of the iOS Simulator if you just delete the SDK. To avoid that, you must also delete the Xcode cache. Then you won't be forced to reinstall the older SDK on launch.

To remove the iOS 5.0 simulator, delete these and then restart Xcode:

  1. /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/PhoneSimulator5.0.sdk
  2. ~/Library/Caches/com.apple.dt.Xcode

For example, after doing a clean install of Xcode, I installed the iOS 5.0 simulator from Xcode preferences. Later, I decided that 5.1 was enough but couldn't remove the 5.0 version. Xcode kept forcing me to reinstall it on launch. After removing both the cache file and the SDK, it no longer asked.

Answers:

September 2017, Xcode 9

You will find them here:

To delete devices go here:

Much easier to delete them use Xcode:
Xcode->Window->Devices and Simulators

Helping Xcode 'forget' about runtimes and prevent from re-installing them – delete .dmg file(s) here:

I hope it will help someone ?

Answers:

In addition to @childno.de answer, your Mac directory

/private/var/db/receipts/

may still contains obsolete iPhoneSimulatorSDK .bom and .plist files like this:

/private/var/db/receipts/com.apple.pkg.iPhoneSimulatorSDK8_4.bom
/private/var/db/receipts/com.apple.pkg.iPhoneSimulatorSDK8_4.plist

These could make your Downloads tab of Xcode's preferences show a tick () for that obsolete simulator version.

To purge the unwanted simulators, you can do a search using this bash command from your Mac terminal:

Xcode Simulator Using All My Memory

sudo find / -name '*PhoneSimulator*'

Then go to corresponding directories to manually delete unwanted SimulatorSDKs

Answers:

I wanted to delete old Device Simulators to free up disk space. I used xCode/Windows/Devices and removed the devices. This did not help.

The size issue was caused by old iOS O/S versions and NOT the device simulators. The iOS versions were using 75GB of space + the ~7GB for xCode 8.3.3.

Delete the iOS version you don't want and free up disk space.

Answers:

The problem with these answers is that, with every Xcode update, menus and locations will change.

Just go to /Applications/Xcode.app/Contents/Developer/Platforms and delete what you don't need. Xcode will start fine. If you're at all concerned then you can simply restore from Trash.

Answers:

In XCode open Window – Devices, then select and remove the outdated simulators.

Answers:

Another thing you can do is to change the Deployment target to the highest value. This will prevent the Scheme Menu from displaying older versions.

To do this go to:
Target->Summary then change the Deployment Target.

Answers:

I tried all answers. None of them worked for me.

What worked for me on Sierra + Xcode 8.2 was going to:

/Library/Developer/CoreSimulator/Devices and deleting all devices.

(Maybe this won't work for you, maybe this is a solution as a standalone, or maybe you have to do this in addition to other answers, but I did all solutions here and so not sure what did the deed). Just be aware that some of the answers here are old and the location of simulator has changed. Snowcrash's answer seems to be most recent.

Answers:

Command+Space

Type ‘simulator'

open the old beta simulator you no longer need.

right-click on it in the dock, then choose Options>'Show in Finder'

Close the app, then remove it from the folder.

🙂

Tags: xcode





broken image