Xcode 9: Could not attach to pid

IosXcodeXcode9

Ios Problem Overview


I've been facing an issue (frequently) with the recent major release of the iOS application development tool - Xcode 9-beta.

It's showing me the following error frequently while running/debugging app in Simulator (iOS 11).

> Could not attach to pid : “2370” >
Ensure <project title> is not already running, and <system username> has permission to debug it.

Here is a snapshot for the same issue:

error message - Could not attach to pid

What would be permanent solution of this issue, as it's disturbing frequently?

Ios Solutions


Solution 1 - Ios

If issue is on OS Mojave and you are trying, like me to run tests on older Xcode version (lower than 10.0), make sure that in your scheme, when you select Test, Debug executable is disabled

enter image description here

You won't be able to debug tests from this point

Solution 2 - Ios

Still not a permanent solution, but I had to quit and restart Xcode as the other solutions did not work for me.

Solution 3 - Ios

This worked for me:

Edit Scheme -> Info -> Executable -> Ask on launch

Credits to @nastya-gorban's answer here

Update

After spending a considerable time with examples on Apple bug report, they basically disregarded the issue as using manual certificates is not "expected".

Long story short, if you don't have a business account and hence multiple developers on the same account, you should be fine with using the automatic signing and should not see the issue.

If you do have a business account with multiple users (which I found it breaks automatic signing), this is their suggestion:

> We suggest that you use automatic signing for your debug builds and > manual signing for your distribution builds.

Solution 4 - Ios

Killing my simulator and then running it again from Xcode.

Solution 5 - Ios

I had this issue too. There seems to be an issue with having two Xcode version installed at the same time. (9.4.1 and 10.0 Beta)

It works with the beta, but not with the stable version. Everything is set to the tools of the Xcode 9.4.1 stable version. I can only run my unit tests with the beta.

After removing the beta, it worked with the stable version.

Solution 6 - Ios

delete derived data and clean the project, wait until processing is complete, this may take some time. The idea is to give some processing time. Works fine after that

Solution 7 - Ios

I have been dealing with this issue for days. I have been able to build but not launch on Simulator, and I get the same "pid:.." error message.

I am using:

  • Xcode v9.2
  • Swift 3.2
  • Building for iOS

The things that I tried that DID NOT WORK were:

restarting the computer; deleting content and settings (of Simulator, I do not have "reset"); uninstalling and reinstalling Xcode; changing "Deployment Target"; changing the device in the simulator's Hardware->Manage Device; deleting Derived Data, Cleaning and Building, or just waiting...forever.

What WORKED was as @Rajasekhar mentioned:

  • checked out the Keychain certificates.
  • deleted the exiting ones by right clicking (they'd passed expiration)
  • and unchecked "automatically manage signing" in Targets->General

After that it successfully launched in Simulator. I don't know if the issue will come back but hopefully this works.

Solution 8 - Ios

Even on Xcode 11.1/2/3

It is an Authorization issue with Simulator, When Simulator does not have the necessary access. It raises the issue.

Try following in Terminal

sudo DevToolsSecurity -enable

or

sudo /usr/sbin/DevToolsSecurity -enable

Details can be found here

Solution 9 - Ios

I hate to add more noise to this, but for me, the answer is to, nonsensically, use sudo.

Run normally, Xcode 9.4.1 (9F2000) and Xcode 10.0 beta 4 (10L213o) both failed to attach to my app after multiple tries, giving the error quoted in the original post.

What worked was to run Xcode (9.4) with sudo,

sudo /Applications/Xcode.app/Contents/MacOS/Xcode

I don't see why sudo is necessary. The Cocoa app to which I am attaching is a Debug build that I just built in Xcode 9.4.1 and dragged into /Applications. It is not codesigned. Posix permissions on the .app, its Contents, its MacOS, and the executable are all octal 755. Owner is me. It works fine if I leave it in the Build folder, build and debug in the normal way.

The problem is apparently with lldb. I also tried using lldb (lldb-902.0.79.7) from the command line. I got the same result. It works only with sudo. Without sudo,

error: attach failed: unable to attach

Solution 10 - Ios

I had same issue. Check screenshot.

Screenshot added

Below are few solutions that should work:

  1. Rerun project
  2. Clean (Shortcut: cmd + shift + K) and Rerun project
  3. Quit Xcode and Simulator. Open project and run again
  4. Reset content of Simulator (Select Simulator -> Goto Hardware tab -> Erase All Content and Settings…) and rerun project.

Screenshot added

Solution 4 worked for me.

Solution 11 - Ios

This seems to be a temporary issue when you are trying to build too fast after a build has started. Try stopping and running the project again.

Solution 12 - Ios

(most likely solution) 1. Simulator-> Hardware-> Erase all contents and Settings

(less likely solution) 2. keychain-> upper right lock-> unlock and lock again (or the other way around)

Solution 13 - Ios

In my case (Xcode 10.1), this was the error in the console:

kernel	macOSTaskPolicy: (com.apple.debugserver) may not get the taskport of (bin) (pid: 10132): (bin) is hardened, (bin) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger

So the solution was disable the Hardened Runtime, clean the build folder and run again.

Solution 14 - Ios

I was seeing this in Xcode 10.2 and the cause for me was that lldb-rpc-server was crashing. I worked around it by ensuring either Address Sanitizer or Thread Sanitizer is enabled in the debug options. I also filed a bug report viewable on Open Radar.

Solution 15 - Ios

I tried all the answers above. The only thing worked to me is changing the build number.

Solution 16 - Ios

This is the issue with the untrusted certificates in key-chain access, please remove such a type of certificates and re-build again.

Solution 17 - Ios

This happens on my machine, when I set the 'new build system' Go to menu file=>workspace settings and set Build System to "Standard".

Solution 18 - Ios

I realise this is not a problem with a single solution, from all the other answers. So, here's what worked for me:

  1. Reboot the machine

  2. The first run always works for me. The only thing that helps me avoid this error after this first run, is to stop the application from XCode, instead of just clicking the Run button to re-run the application.

Another thing, when I lock my computer the issue re-appears sometimes (probably when I forget to stop the application). So I have to reboot my machine again.

Solution 19 - Ios

After doing some digging, this worked for me on Xcode 10.3.

sudo /usr/sbin/DevToolsSecurity -enable

Solution 20 - Ios

In my case the only thing that worked was switching back from the "New Build System" to the "Legacy Build System" in the Workspace Settings. Bummer.

Solution 21 - Ios

It's an issue with authorization. Try this in the Terminal:

sudo DevToolsSecurity -enable

Solution 22 - Ios

First, close app completely via sim (not sleep - close app totally) If not working yet: reboot whole PC, ensure only 1 simulator is active upon reboot.

More than 1 sim can confuse it if it's bugging.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKrunalView Question on Stackoverflow
Solution 1 - Iosninja_iOSView Answer on Stackoverflow
Solution 2 - IosPicklesIIDXView Answer on Stackoverflow
Solution 3 - IosEfrenView Answer on Stackoverflow
Solution 4 - Iosuser2421755View Answer on Stackoverflow
Solution 5 - Iosuser1199624View Answer on Stackoverflow
Solution 6 - IosDivyaView Answer on Stackoverflow
Solution 7 - IostameikalView Answer on Stackoverflow
Solution 8 - IosNasirView Answer on Stackoverflow
Solution 9 - IosJerry KrinockView Answer on Stackoverflow
Solution 10 - IosJayprakash DubeyView Answer on Stackoverflow
Solution 11 - IosTamás SengelView Answer on Stackoverflow
Solution 12 - IosWill GwoView Answer on Stackoverflow
Solution 13 - IosaoneView Answer on Stackoverflow
Solution 14 - IosRudedogView Answer on Stackoverflow
Solution 15 - IosmahdiView Answer on Stackoverflow
Solution 16 - IosRajasekhar PasupuletiView Answer on Stackoverflow
Solution 17 - IosThorstenCView Answer on Stackoverflow
Solution 18 - Iosanatp2015View Answer on Stackoverflow
Solution 19 - IosWillView Answer on Stackoverflow
Solution 20 - IosRiveraView Answer on Stackoverflow
Solution 21 - IosWaris ShamsView Answer on Stackoverflow
Solution 22 - IosStephen JView Answer on Stackoverflow