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!

larsschwegmann
  • 725
  • 1
  • 6
  • 14
  • 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](http://www.blog.montgomerie.net/easy-xcode-static-library-subprojects-and-submodules).. so in my case is there a setting or something i can do to stop this thing from showing up? – abbood Jan 16 '13 at 12:42
  • 1
    This same question appears 3 times: [__one__](http://stackoverflow.com/questions/12741188/error-failed-to-attach-to-process-id-0) [__two__](http://stackoverflow.com/questions/9702201/xcode-compiles-my-app-but-cant-run-it-in-the-simulator) [__three__](http://stackoverflow.com/questions/11535844/failed-to-attach-to-process-id-xcode). There are tons of answers under each, so if this one didn't help you, check the other 2. – bobobobo Apr 21 '13 at 22:04
  • Make sure you don't have any files named with a keyword used by xcode. Eg: default / delete / resource etc. – user2731193 Aug 30 '13 at 00:45

20 Answers20

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
Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139
Lindemann
  • 3,336
  • 3
  • 29
  • 27
11

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

twilson
  • 2,062
  • 14
  • 19
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://stackoverflow.com/a/1265168/649

Community
  • 1
  • 1
beno
  • 2,160
  • 1
  • 25
  • 24
  • 2
    The issue with the 'reference folder' called Resources is what caused the problem for me. – Ricardo Sanchez-Saez Oct 09 '12 at 13:33
  • +1 I think there should be a greater emphasise for the resources folder issue as this was clearly the case for me. – eladleb Nov 04 '12 at 10:32
  • +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. – Chris Ching Apr 04 '13 at 03:31
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.

j0k
  • 22,600
  • 28
  • 79
  • 90
Ran Rubinstein
  • 2,305
  • 1
  • 14
  • 7
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.

Pablo
  • 613
  • 5
  • 12
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
xxtesaxx
  • 6,175
  • 2
  • 31
  • 50
1

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

nzeltzer
  • 521
  • 4
  • 9
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.

Jason
  • 519
  • 6
  • 14
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.

Toby
  • 957
  • 2
  • 14
  • 34
  • 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 `CFBundleIdentifier` – Toby Jan 26 '13 at 17:16
  • 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. – bobobobo Apr 06 '13 at 17:21
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://stackoverflow.com/a/12504712/2069749) solved the problem for me.

Community
  • 1
  • 1
Prashant
  • 1,014
  • 11
  • 28
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).

j-a
  • 1,780
  • 1
  • 21
  • 19
0

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

matthias krull
  • 4,389
  • 3
  • 34
  • 54
vovtil
  • 11
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.

zakishaheen
  • 5,551
  • 1
  • 22
  • 29
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.

j0k
  • 22,600
  • 28
  • 79
  • 90
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.

krishnan
  • 782
  • 1
  • 9
  • 20
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

Philip J. Fry
  • 1,165
  • 1
  • 8
  • 10
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.

MkVal
  • 1,044
  • 1
  • 11
  • 17
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.

rmadams
  • 1
  • 1
-2

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

Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58
Petros
  • 1
-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.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
larsschwegmann
  • 725
  • 1
  • 6
  • 14
  • 10
    This isn't really fixing the problem at all, it's avoiding the problem. – Daniel Thorpe Sep 28 '12 at 11:17
  • Consider switching your "approved" answer. – Olie Aug 10 '13 at 01:16
  • 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. – larsschwegmann Nov 22 '13 at 17:10