16

Today, when I try to run my app in simulator, it simply tells me

Unable to run app in Simulator
An error was encountered while running
(Domain = NSPOSIXErrorDomain, Code = 22)

And the error dialog looks like this:

Unable to run app in Simulator

I've tried many things:

  • Restart Xcode
  • Restart Simulator
  • Reboot
  • Reset content and settings of simulator

None of above works. And I looked into log, I found these are those records has something to do with this issue

2014/10/15 9:09:40.964 com.apple.CoreSimulator.CoreSimulatorService[979]: Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7f96c861d000 {NSLocalizedDescription=Unable to lookup in current state: Shutdown}

2014/10/15 9:09:40.964 Xcode[1983]: [MT] iPhoneSimulator: Unable to connect to "com.apple.instruments.deviceservice.lockdown" (Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7fcf6fc24190 {NSLocalizedDescription=Unable to lookup in current state: Shutdown})

2014/10/15 9:09:40.980 com.apple.CoreSimulator.CoreSimulatorService[979]: Error Domain=com.apple.CoreSimulator.SimError Code=146 "Unable to lookup in current state: Shutdown" UserInfo=0x7f96c861d000 {NSLocalizedDescription=Unable to lookup in current state: Shutdown}

2014/10/15 9:09:42.351 launchd_sim[2047]: assertion failed: 13F34: libxpc.dylib + 29453 [75E30F22-514B-3A20-B82C-EDA43AF5C35C]: 0x8d

2014/10/15 9:09:42.362 com.apple.CoreSimulator.CoreSimulatorService[979]: Could not register service com.apple.coreservices.lsuseractivity.simulatorsupport: Failed to lookup com.apple.coreservices.lsuseractivity.simulatorsupport: 0x44e

I also found some other people had the same issue here : https://gist.github.com/bdeshong/2dd90add09b7287a9a85

No luck to find solution after Googling around.

Here is my environment information

  • OSX 10.9.5
  • Xcode 6.0.1
  • iOS Simulator 8.0 (550.1)

Any ideas?

Community
  • 1
  • 1
Fang-Pen Lin
  • 13,420
  • 15
  • 66
  • 96
  • 1
    check this answer http://stackoverflow.com/questions/24727397/xcode-beta-6-ios-8-simulator-not-working/25415781#25415781 – Sunny Shah Oct 16 '14 at 06:00
  • @SidShah it's already selecting 6.0.1 command line tool – Fang-Pen Lin Oct 16 '14 at 06:05
  • try casariegj answer that works for me.. – Sunny Shah Oct 16 '14 at 06:06
  • For me, I wound up having to Clean and Build again. As far as I could tell the only difference between everything being happy and everything being said was that I switched screen sizes. Which makes no sense. Feels like something finicky at a low level, but a Clean / Build fixed it. – kiminoa Mar 11 '15 at 23:46
  • had a different error message: "Failed to install application, Invalid Argument". But solution was the same. – John Apr 27 '15 at 00:19

8 Answers8

20

I found the root causes, and I also found the solution. First thing I've done is to ensure this has something to do with Xcode rather than a problem relative to the project itself. I tried to create a new project, and it works perfectly fine. So I assume that is caused by something in my project.

I actually added a resources reference folder to my project. So I think the problem has something to do with it. However, even I removed the folder from project, the problem is still there. In the end, it turns out, the resources folder could live in

  • Built App folder
  • App folder in simulator

Since Xcode may simply copy and overwrite target App bundle folder, so the resources folder may still there in the App bundle folder. So after removing the resources folder, you need to

  • Ensure the build is cleaned
  • Ensure the app in simulator is deleted

And for the reason the App cannot be launched correctly, that's because it appears resources is actually a reserved folder name in the bundle structure. By adding a folder named resources into the bundle, somehow ruined the normal structure. To solve the problem, I changed the name from resources to app_data, or whatever it is, that all work.

Fang-Pen Lin
  • 13,420
  • 15
  • 66
  • 96
  • 1
    unbelievable, I wonder if there's any reference to this in the documentation. I just spent an afternoon trying to figure out what the problem was, turns out I too added a resources folder reference... – Dario Nov 03 '14 at 23:20
  • 1
    You sir a scholar and a gentleman. And a genius. You need to accept your own answer because you totally deserve that +2. – Ohad Schneider Nov 09 '14 at 17:45
  • @Dario Please see https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/20001119-110730, the `Resources` folder is used by the app bundle folder structure. – Fang-Pen Lin Nov 10 '14 at 18:17
  • @VictorLin Please look at that page again, the `resources` folder is clearly used in the example Mac app (listings 2-3 and 2-4) but it is not referenced in iOS apps (listings 2-2 and 2-3). This question is specifically labeled iOS and, although the assumption that someone at apple was too lazy to implement different bundle rules for the different bundle structures can be made, the documentation does not reference the `resources` folder as being reserved in iOS apps. – Dario Nov 11 '14 at 04:25
  • @Dario hmmm, sorry, then I have no idea where is the reserved name `resources` from. But my bet is, Apple will reuse their existing library as much as possible, I don't think they want to waste time to build something they already have. So I think it's highly possible iOS bundle structure inherits something from Mac app bundle. – Fang-Pen Lin Dec 05 '14 at 20:05
  • Same error, but the cause lay in duplicate base.lproj en en.lproj folders, one set empty, the other not. – Elise van Looij Jan 05 '15 at 13:45
6

I got the same. I just did force quit xcode and simulator then worked for me.

user3616535
  • 119
  • 1
  • 9
1

You are doing everything correct but Xcode and Swift are still in their early stages, means they are a little buggy right now. Maybe try restarting your Xcode and iOS Simulator once more.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
alex
  • 1,746
  • 6
  • 19
  • 34
  • 1
    hey, Rusher, I've tried to restart the Xcode and the Simulator, but it doesn't work. Anyway, thanks for your advice. I recall when I was 13 years old, I was developing my own MMORPG with Visual Basic 6.0. Internet sounds like this http://youtu.be/vvr9AMWEU-c by the time. I was lucky that I found what I want to do at very young age, I bet you're too. Just want to say, do what you want to do, keep going, and enjoy it :) – Fang-Pen Lin Oct 16 '14 at 05:07
  • @VictorLin thanks for the support man! I've had this error but what I told you worked for me. The only way I would be able to fix this is delete the app and re-download this may take a while, but I think it would be well worth it! May you please make sure if this post helped you upvote and check the answer it would really help. Thanks – alex Oct 16 '14 at 05:12
  • sorry but your solution doesn't help in my case :P – Fang-Pen Lin Oct 16 '14 at 05:15
  • Did you try deleting and re-downloading the app? – alex Oct 16 '14 at 05:19
  • your answer didn't solve the whole problem, however, since your suggestion about deleting app is somehow helpful, so thank you for that, although I posted my own whole root causes and solution, still I up voted your answer. – Fang-Pen Lin Oct 17 '14 at 02:55
  • Editor note: Please reply to the original post rather than create an answer. Failing to do this will otherwise makes this post bound to be deleted by the SO editors. – Ricardo Zea Jul 27 '15 at 14:19
1

I got the exact same error. When browsing in my project info I inadvertently deleted the bundle identifier; hence the "ErrorDomain".

to correct, goto project data; info; set bundle identifier to whatever it was. it worked for me.

Guy
  • 11
  • 1
0

This can happen for a couple of reasons:

  1. You quit the iOS Simulator.app while Instruments was trying to use it.
  2. You changed the booted device in the iOS Simulator.app while Instruments was trying to use another one.

If neither of those is the case, take a look at ~/Library/Logs/CoreSimulator/*.log for more information that might help debugging and include it in your question.

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
0

Root cause in my case was slightly different. In the project file, the iOS deployment target was set to 8.0 for the test target and 8.1 for the main target. We were running Xcode 6.0.1 (6A317) with 8.0 simulators on our build servers, which all started failing after the main build target was set to 8.1.

I'm not sure whether it was the fact that the target and tests were using different iOS deployment targets, or whether the 8.1 set in the project file conflicted with the 8.0 simulators, but it was this change which broke the simulators across several machines.

Unfortunately after setting the iOS Deployment Target back to 8.0 in the project, it still required a reinstall of Xcode (I also removed the ~/Library/Developer/Xcode directory) to return simulators to a functional state.

0

Check if you have proper permissions on your /private/tmp folder, should be writable and executable for all users.

-1

Clear all files in /Users/XXXXX/Library/Developer/CoreSimulator/Devices

Restart Xcode and Simulator.

Now it will work.

Balaji G
  • 77
  • 5