ios Xcode 9:无法附加到 pid

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44651029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:15:41  来源:igfitidea点击:

Xcode 9: Could not attach to pid

iosxcodexcode9

提问by Krunal

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

最近 iOS 应用程序开发工具的主要版本 - Xcode 9-beta 中,我一直面临一个问题(经常)。

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

在模拟器(iOS 11)中运行/调试应用程序时,它经常向我显示以下错误。

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

无法附加到 pid : “2370”
确保 <项目名称> 尚未运行,并且 <系统用户名> 具有调试权限。

Here is a snapshot for the same issue:

这是同一问题的快照:

error message - Could not attach to pid

错误消息 - 无法附加到 pid

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

这个问题的永久解决方案是什么,因为它经常令人不安?

回答by ninja_iOS

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

如果问题出在OS Mojave 上并且您像我一样尝试在较旧的 Xcode 版本(低于 10.0)上运行测试,请确保在您的方案中,当您选择测试时,调试可执行文件被禁用

enter image description here

在此处输入图片说明

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

您将无法从此时开始调试测试

回答by PicklesIIDX

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

仍然不是永久的解决方案,但我不得不退出并重新启动 Xcode,因为其他解决方案对我不起作用。

回答by Efren

This worked for me:

这对我有用:

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

编辑方案 -> 信息 -> 可执行文件 -> 启动时询问

Credits to @nastya-gorban's answer here

归功于@nastya-gorban在此处的回答

Update

更新

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

在花了大量时间研究 Apple 错误报告的示例之后,他们基本上忽略了这个问题,因为使用手动证书不是“预期的”。

Long story short, if you don't have a business accountand hence multiple developers on the same account, you should be fine with using the automatic signingand 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.

我们建议您对调试版本使用自动签名,对分发版本使用手动签名。

回答by user2421755

Killing my simulator and then running it again from Xcode.

杀死我的模拟器,然后从 Xcode 再次运行它。

回答by Saif

I too faced the same issue, I was trying to run the test cases with older version of xcode (9.4 in my case).

我也遇到了同样的问题,我试图用旧版本的 xcode(在我的例子中是 9.4)运行测试用例。

Disabling Debug Executableworked. enter image description here

禁用Debug Executable工作。 在此处输入图片说明

回答by Maik639

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)

我也有这个问题。同时安装两个 Xcode 版本似乎存在问题。(9.4.1 和 10.0 测试版)

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.

它适用于测试版,但不适用于稳定版。一切都设置为 Xcode 9.4.1 稳定版的工具。我只能用 beta 运行我的单元测试。

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

删除测试版后,它可以与稳定版本一起使用。

回答by tameikal

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.

我已经处理这个问题好几天了。我已经能够在模拟器上构建但无法启动,并且收到相同的“pid:...”错误消息。

I am using: - Xcode v9.2 - Swift 3.2 - Building for iOS

我正在使用: - Xcode v9.2 - Swift 3.2 - 为 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.

重新启动计算机;删除内容和设置(模拟器的,我没有“重置”);卸载并重新安装 Xcode;改变“部署目标”;在模拟器的硬件->管理设备中更改设备;删除派生数据、清理和构建,或者只是等待......永远。

What WORKED was as @Rajasekhar mentioned:

正如@Rajasekhar 所提到的,有效的是:

  • checked out the Keychain certificates.
  • deleted the exiting ones by right clicking (they'd passed expiration)
  • and unchecked "automatically manage signing" in Targets->General
  • 签出钥匙串证书。
  • 通过右键单击删除现有的(它们已经过期)
  • 并在 Targets->General 中取消选中“自动管理签名”

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

之后它在模拟器中成功启动。我不知道问题是否会再次出现,但希望这有效。

回答by Nasir

Even on Xcode 11.1/2/3

即使在 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

sudo DevToolsSecurity -enable

or

或者

sudo /usr/sbin/DevToolsSecurity -enable

sudo /usr/sbin/DevToolsSecurity -enable

Details can be found here

详细信息可以在这里找到

回答by Divya

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

删除派生数据并清理项目,等待处理完成,这可能需要一些时间。这个想法是给一些处理时间。在那之后工作正常

回答by Jerry Krinock

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

我不想为此添加更多噪音,但对我来说,答案是荒谬地使用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.

运行正常,Xcode 9.4.1 (9F2000) 和 Xcode 10.0 beta 4 (10L213o) 在多次尝试后都未能附加到我的应用程序,给出了原始帖子中引用的错误。

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

有效的是使用 sudo 运行 Xcode (9.4),

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

I don't see why sudois 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.

我不明白为什么sudo有必要。我附加的 Cocoa 应用程序是我刚刚在 Xcode 9.4.1 中构建并拖入/Applications. 它不是代码设计的。.app、 its Contents、 itsMacOS和可执行文件的Posix 权限均为八进制 755。所有者是我。如果我将它保留在 Build 文件夹中,以正常方式构建和调试,它就可以正常工作。

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,

问题显然出在 lldb 上。我还尝试从命令行使用 lldb (lldb-902.0.79.7)。我得到了同样的结果。它仅适用于sudo. 没有sudo,

error: attach failed: unable to attach