-->

Unable to run app in simulator

2020-08-13 02:32发布

问题:

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:

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?

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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.



回答5:

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.



回答6:

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



回答7:

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



回答8:

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

Restart Xcode and Simulator.

Now it will work.