Xcode compiles my App, but can't run it in the simulator
Asked Answered
H

20

54

when i compile my app, Xcode just says "Attaching to Projectname..." and gets stuck there. The debugger just prints this out:

error: failed to attach to process ID 0

I tried to clean & build again and it still doesn't work out. I googled but couldn't find anything helpful. How can I fix this problem? Thank You!

Harbot answered 14/3, 2012 at 12:42 Comment(3)
i think this should be added to the question: why does it happen and how can it be prevented? in my case i started seeing this problem often after i've started editing a static library that's dynamically linked.. so in my case is there a setting or something i can do to stop this thing from showing up?Heinrich
This same question appears 3 times: one two three. There are tons of answers under each, so if this one didn't help you, check the other 2.Ferrocyanide
Make sure you don't have any files named with a keyword used by xcode. Eg: default / delete / resource etc.Zoroastrian
U
75

The solution for me was to delete everything Xcode has generated earlier:

  • the App on the Simulator...if this is not possible because you cant reach the Homescreen, you can delete the App directly under ~/Library/Application Support/iPhoneSimulator/6.0/Applications
  • delete the Derived Data in the Organizer under Projects or directly in ~/Library/Developer/Xcode/DerivedData
  • clean the Build Folder by choosing "Product" in the MenuBar and click while you press the Alt-key on "Clean Build Folder"
  • Restart Xcode
Usa answered 20/9, 2012 at 0:35 Comment(6)
It took all three steps for me. +1Herries
2nd and 3rd steps together with restart worked for me. Thanks.Beaner
1. IOS Simulator > Reset Content and Setting - in Simulator 2. Product > Clean - in xCode 3. Re BuildIdyllist
its too bad apple doesnt have the resources to fix this bug. Thanks to Lindermann for the workaround!!Healthful
I don't have ~/Library/ApplicationRegin
@Regin The ~/Library Folder is hidden for the user since OSX 10.7. Just google for "Mountain Lion Library Folder" or something like this and you will find 545465 tutorial which will explain how to get access to this folder.Usa
L
11

Have you tried closing down the simulator entirely, or failing that, reset the simulator and all its contents usually does the trick.

Limiting answered 14/3, 2012 at 12:45 Comment(1)
He actually meant reset THE SIMULATOR itself.Stuckey
F
8

What finally got the simulator working again for me was deleting everything under Library/Application Support/iPhone Simulator/ within the user directory. What I think caused the problem for me in the first place was trying to use a directory named 'Resources' as described here: https://mcmap.net/q/190186/-failed-to-launch-simulated-application-unknown-error

Fransen answered 27/8, 2012 at 18:57 Comment(3)
The issue with the 'reference folder' called Resources is what caused the problem for me.Deane
+1 I think there should be a greater emphasise for the resources folder issue as this was clearly the case for me.Etzel
+1 If you add a folder reference named Resources, this seems to happen. This was with XCode 4.6. I had to remove the Resources folder reference and do a clean in order to fix it.Deviate
P
6

This happened to me when I had two xcode projects open with the same bundle identifier.

Solution: leave only one project open which has the same bundle id.

Poss answered 12/8, 2012 at 12:33 Comment(0)
T
4

Lindemann's solution worked for me. Nonetheless, during further development I came across another situation that generates this problem: if you create a folder reference (blue folder on Xcode's file explorer, as opposed to the yellow ones which are just groups) called "Resources" the same issue will arise. The solution in this case is to simply rename that folder. After this, follow Lindemann's solution.

Theressathereto answered 7/3, 2013 at 19:34 Comment(3)
you mean Lindemann (I was searching for Lindermann in the page and found nothing...)Koral
Are you serious!? +100000 Thanks so much! All working now!Ettaettari
OMG! I got the same issue!Potts
S
2

I had similar issues when i installed XCode 4.5 on OS X Mountain Lion. I searched a while and tried some fixes but what finally solved the problem was adding "127.0.0.1 localhost" to my hosts file (/etc/hosts).

Here is what i have done:

Open a terminal shell with cmd+space > terminal
type in "cd /etc"
type in "sudo nano hosts"
type in your root password
add "127.0.0.1 localhost"
save with ctrl+o > return
close with ctrl+x
log out and log in again or restart
Seema answered 13/12, 2012 at 21:18 Comment(0)
J
1

Ctrl-Shift-Option-K (same as holding down option and selecting Product ... Clean Build Folder) has always worked for me.

Justiciable answered 26/4, 2012 at 17:57 Comment(0)
F
1

What seemed to work for me was build & run my code so that it opened the Simulator, then hold down on the Simulator Icon in the Dock and select Options -> Keep In Dock

After this I just closed the simulator and launched it from the dock and deleted the app from the home screen on the simulator.

Build & Run the app from XCode and everything seemed to be OK again.

Fool answered 10/10, 2012 at 0:29 Comment(0)
S
1

There seems to be quite a lot of things that can cause this error, but for me it turned out to be that I was missing the key CFBundleIdentifier from my plist.

Added it back, and the simulator started normally.

Strander answered 26/1, 2013 at 17:12 Comment(2)
Just doing some more testing on this, seems the only two keys you actually need in the plist to get your app to run on the simulator is CFBundleExecutable and CFBundleIdentifierStrander
Yes, this was exactly my problem. I downloaded a project from Google Code and the CFBundleIdentifier had been removed. Restoring the default value of w.${PRODUCT_NAME:rfc1034identifier} fixed the problem.Ferrocyanide
I
1

Also make sure none of your file/group name collide with the projects default settings.

Things started breaking for me when I added an info.plist file to my project (Bad Idea). Same happens when you add a "Resource" Group. I don't have an exhaustive list, but if someone does please do share.

Cleaning out / Renaming these conflicting files and following the solution provided by Lindemann(https://mcmap.net/q/189410/-xcode-compiles-my-app-but-can-39-t-run-it-in-the-simulator) solved the problem for me.

Inelastic answered 11/8, 2013 at 22:4 Comment(0)
T
0

Make sure you do not have an invalid build rule, that will cause this error, happened to me once (I had added a build rule by mistake and left it invalid).

Tanta answered 16/6, 2012 at 14:5 Comment(0)
L
0

You need to change the debbugger LLDB to GDB. This helped me start my program in the simulator.

Less answered 28/8, 2012 at 8:16 Comment(0)
S
0

What worked for me was that I realized i was messing with the project settings and accidently removed the info-plist section. After specifying the plist file again properly, it worked. Hope that helps someone.

Sadowski answered 4/10, 2012 at 12:50 Comment(0)
T
0

If you are using a network account, you should replace the "~/Library/Application Support/iPhone Simulator" with a link to a local directory. This worked for me after trying everything else.

Tompion answered 28/11, 2012 at 8:19 Comment(0)
S
0

I had the same problem, in my case i have left the ios simulator open in one user account and switched (without logout the previous one) to another user account. I couldn't event able to open ios simulator to clear and reset its settings. [Shows could no open ios simulator OSStatus - 10829]

My solution: I quit the simulator in the first user account and then came back to second user account, every thing is working fine.

Shillelagh answered 24/5, 2013 at 7:36 Comment(0)
A
0

try to do next steps:

  • Go to Product/Scheme/Edit Scheme then select Run section.
  • Select Info Tan and set Debugger None.
  • Run project. It must be working (without debugger)
  • Go back to Edit Scheme and selecet debugger LLDB
  • Run project. It is working.

Maybe additionally you need to delete derived data and do Product/Clean

Authoritarian answered 30/7, 2013 at 8:53 Comment(0)
O
0

Can't tell you how frustrated I am trying to narrow down the cause of this one. Took me hours. Trial and error here and there.. all leads to nothing until one comment in one of the threads relating to this mentioned about "Executable". Boom! I remember the plist key "Executable file" in my project plist (PROJECT-info.plist). So I got there and found out that that entry was missing. I filled it in with whatever default you see when creating new project, "Executable file" paired with "${EXECUTABLE_NAME}". Build + Run. Then it finally worked!

Btw, I did try all those deleting/resetting stuff found all over SO. None of them works.

Oof answered 17/10, 2013 at 5:44 Comment(0)
S
0

If resetting content and settings in the Simulator doe snot work for you, make sure that there is an entry for localhost in your /etc/hosts file:

127.0.0.1 localhost

Some programs can delete the line or comment it out (#) or even delete your /etc/hosts/ file completely. I tried everything described, but once I added localhost back to the file, the simulator worked perfectly for me.

Sadirah answered 23/7, 2014 at 13:31 Comment(0)
K
-2

What worked for me was to select 'Delete Derived Data' from the Projects tab in the organiser.

Killifish answered 27/9, 2012 at 11:42 Comment(0)
H
-12

I fixed my problem by I making a new blank project and importing all the old files.

It must have been a problem with Xcode because it worked before iOS 5.1.

Harbot answered 24/3, 2012 at 8:55 Comment(3)
This isn't really fixing the problem at all, it's avoiding the problem.Buchner
Consider switching your "approved" answer.Delorisdelorme
I wrote that when there was no other solution. None of the "fixes" posted here at that time worked for me so I avoided the problem. I needed to get going with my project and couldn't wait until september. Never had that issue again. I changed the accepted answer.Harbot

© 2022 - 2024 — McMap. All rights reserved.