Xcode 7 - 代码覆盖率数据生成失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32223965/
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
Xcode 7 - Code coverage data generation failed
提问by Bart?omiej Semańczyk
When I run my tests I get an error:
当我运行我的测试时,我收到一个错误:
Code coverage data generation failed.
Unable to retrieve the profile data files from 'UIDevice'.
代码覆盖率数据生成失败。
无法从“UIDevice”检索配置文件数据文件。
On console was printed warning:
在控制台打印警告:
Timed out waiting 120 seconds for simulator to boot, current state is 1.
超时等待 120 秒模拟器启动,当前状态为 1。
What is the reason?
是什么原因?
回答by Cruinh
If you are integrating your project with a 3rd party dynamic framework, you may need to add a path in your build settings. Look for ->Build Settings->"Runpath search paths" and make sure it includes the path to the framework.
如果您将项目与 3rd 方动态框架集成,则可能需要在构建设置中添加路径。查找 ->Build Settings->"Runpath search paths"并确保它包含框架的路径。
I was just seeing this exact issue myself after setting up my a project to use a framework my team has been working on. After updating this specific setting, the problem went away. In my case, the path was identical to one I already had to set for the "Framework search paths" setting.
在设置我的项目以使用我的团队一直在研究的框架后,我自己刚刚看到了这个确切的问题。更新此特定设置后,问题就消失了。就我而言,路径与我已经为“框架搜索路径”设置设置的路径相同。
回答by MarkHim
I solved this problem, just like I solve most of those XCode Problems:
我解决了这个问题,就像我解决了大多数 XCode 问题一样:
- delete your projects files in your
DerivedData
(Xcode>Preferences>Locations>DerivedData→
to jump there in finder) Product>Clean
- (keep alt-Button pressed)
Product>Clean Build Folder
- Quit XCode
- Restart XCode
- Remove your app from your device / simulator
- 删除您的项目文件
DerivedData
(Xcode>Preferences>Locations>DerivedData→
以在查找器中跳转) Product>Clean
- (按住 alt 按钮)
Product>Clean Build Folder
- 退出 XCode
- 重启 XCode
- 从您的设备/模拟器中删除您的应用
Try again. In case it still doesn't work, use another simulator / device for a few runs. Sooner or later it will work again on the original one again.
再试一次。如果它仍然不起作用,请使用另一个模拟器/设备运行几次。迟早它会再次在原始版本上工作。
回答by Nuno Gon?alves
If you are using cocoa pods, check this thread on the Cocoapods repository: https://github.com/CocoaPods/CocoaPods/issues/5385#issuecomment-226269847
如果您使用的是可可豆荚,请在 Cocoapods 存储库上查看此线程:https: //github.com/CocoaPods/CocoaPods/issues/5385#issuecomment-226269847
This fixed my problem:
这解决了我的问题:
Copying @dfleming response:
复制@dfleming 回复:
For some reason, it appears that CocoaPods is not adding the "[CP] Embed Pods Frameworks" build phase to the UI Tests target when generating the project workspace.
I manually added this in and the UI Tests were runnable again.
This build phase should run the following script: (Replace {YourProject} with your project name)
"${SRCROOT}/Pods/Target Support Files/Pods-{YourProject}UITests/Pods-{YourProject}UITests-frameworks.sh"
出于某种原因,在生成项目工作区时,CocoaPods 似乎没有将“[CP] Embed Pods Frameworks”构建阶段添加到 UI 测试目标。
我手动添加了这个,UI 测试又可以运行了。
此构建阶段应运行以下脚本:(将 {YourProject} 替换为您的项目名称)
"${SRCROOT}/Pods/Target Support Files/Pods-{YourProject}UITests/Pods-{YourProject}UITests-frameworks.sh"
回答by danfordham
I experienced exactly the same error and eventually got it working, these are the steps I took.
我遇到了完全相同的错误并最终使其正常工作,这些是我采取的步骤。
Tried restarting Xcode and the simulator, after cleaning and deleting the app, that never worked.
Then I restarted the Mac as suggested, but that still didn't work.
Then I chose a new device to test against in the simulator, was previously using 5s and switched to 6, and that worked.
在清理和删除应用程序后,尝试重新启动 Xcode 和模拟器,但从未奏效。
然后我按照建议重新启动了 Mac,但这仍然不起作用。
然后我在模拟器中选择了一个新设备进行测试,之前使用 5s 并切换到 6,并且有效。
Interestingly, when I switched to the iPhone 6 simulator, it showed the Apple logo with a loading bar, before running the app and working.
有趣的是,当我切换到 iPhone 6 模拟器时,它在运行应用程序和工作之前显示了带有加载栏的 Apple 标志。
When switching back to the 5s simulator it did exactly the same, with the Apple loading bar, which it hadn't done before, and then the 5s worked.
当切换回 5s 模拟器时,它完全相同,使用 Apple 加载栏,这是它以前没有做过的,然后 5s 工作了。
So it looks to be a simulator issue, and switching to a different device worked. Resetting the content and settings may be the solution for a non-working device.
所以它看起来是一个模拟器问题,切换到不同的设备工作。重置内容和设置可能是非工作设备的解决方案。
回答by Tucker Sherman
Cocoapods link_with
method can cause this issue!
Cocoapodslink_with
方法可能会导致此问题!
I was getting the exact same error on xcode 7.2 - no number of simulator or device resets seemed to clear it up. After completely rebuilding my UITest targets though things worked fine. After spending a lot of time in a massive git diff of the .pbxproj
file I found a solution for my project. Im not sure if it addresses the root cause for everyone who is seeing this error but it definitely clears things up for me.
我在 xcode 7.2 上遇到了完全相同的错误 - 似乎没有多少模拟器或设备重置可以清除它。在完全重建我的 UITest 目标后,虽然一切正常。在.pbxproj
文件的大量 git diff 中花费了大量时间后,我为我的项目找到了解决方案。我不确定它是否解决了看到此错误的每个人的根本原因,但它确实为我解决了问题。
From the project info below "deployment target", "Configurations" will list all the possible configurations for your application. Expand the configuration you are trying to run and you should see a list of all your targets. In my case cocoapods had automatically added a base configuration for the UITest target:
从“部署目标”下方的项目信息中,“配置”将列出您的应用程序的所有可能配置。展开您尝试运行的配置,您应该会看到所有目标的列表。在我的例子中,cocoapods 自动为 UITest 目标添加了一个基本配置:
Set this to none
in the dropdown.
Next in the menu to the left select your UITest target then build phases
You will need to remove check pods manifest.lock
link binary with libraries
emebd pods frameworks
and copy pods resources
.
none
在下拉菜单中将其设置为。
接下来在左侧的菜单中选择您的 UITest 目标,然后build phases
您将需要删除check pods manifest.lock
link binary with libraries
emebd pods frameworks
和copy pods resources
。
Finally go to your pod file and check for any mentions of your UITest target or targets. In my case I had been specifying at the top of my podfile:
最后转到您的 pod 文件并检查是否提及您的 UITest 目标。就我而言,我一直在 podfile 的顶部指定:
platform :ios, '8.4'
use_frameworks!
link_with 'My App', 'My UITesting Target'
pod 'A Pod', '~> 1.0'
Instead the podfile should list specific dependencies for each target:
相反,podfile 应该列出每个目标的特定依赖项:
platform :ios, '8.4'
use_frameworks!
target 'My App', :exclusive => true do
pod 'A Pod I want to use in my app', '~> 1.0'
end
Assuming you weren't using any pods in your UITests the target should build again without errors and tests will run!
假设您没有在 UITests 中使用任何 pod,目标应该再次构建而不会出错,并且测试将运行!
My understanding of root of this problem is that each UITest target builds two separate bundles, one for the app and one for the UITest controller. Unfortunately cocoapods link_with
logic modifies all the specified targets to expect the pods.framework in their bundle. The build phase scripts add the framework to the app bundle but not the UITest controller bundle, so then when you launch your tests that UITest controller bundle appears to be missing frameworks and xcode aborts the installation.
我对这个问题的根源的理解是每个 UITest 目标构建两个单独的包,一个用于应用程序,一个用于 UITest 控制器。不幸的是,cocoapodslink_with
逻辑修改了所有指定的目标,以期望它们的包中包含 pods.framework。构建阶段脚本将框架添加到应用程序包而不是 UITest 控制器包,因此当您启动测试时,UITest 控制器包似乎缺少框架并且 xcode 中止安装。
If you were using pods in your UITests you should be able to specify these in the same way:
如果您在 UITests 中使用 pods,您应该能够以相同的方式指定这些:
target 'My UITesting Target', :exclusive => true do
pod 'Another Pod I want only for UITesting', '~> 1.0'
end
And when you run pod install
everything should link up correctly.
当你运行时,pod install
一切都应该正确链接。
回答by balkoth
This problem can also appears when you use Cocoapods with a framework where some dependencies are missing. For example if you are using Framework A, and this framework depends of Framework Bbut in the Podspec of Framework Athe dependency is not declared.
当您将 Cocoapods 与缺少某些依赖项的框架一起使用时,也会出现此问题。例如,如果您使用的是Framework A,并且此框架依赖于Framework B但在Framework A的Podspec 中未声明依赖项。
回答by Henry Sou
My problem was caused by incorrect deployment version of unittest target. Tested App deployment version was 7.0, but the unittest's was not set up correctly automatically. It was set to 10.0, while my simulator's version was 8.4. Change the UT target's deployment version to 8.0 in build settings and then all the problems disappeared.
我的问题是由 unittest 目标的不正确部署版本引起的。测试应用程序部署版本为 7.0,但未自动正确设置单元测试。它被设置为 10.0,而我的模拟器的版本是 8.4。在构建设置中将UT目标的部署版本更改为8.0,然后所有问题都消失了。
回答by Mustafa
One of the reasons this can happen is if the host application that the test target is testing is not linked to the right dependencies. For example, if you have are testing a framework, make sure the host app is linked to those frameworks and also embedded.
发生这种情况的原因之一是测试目标正在测试的主机应用程序未链接到正确的依赖项。例如,如果您正在测试一个框架,请确保宿主应用程序链接到这些框架并嵌入。
回答by Miro
I tried a bunch of these solutions with no luck. I turned off the Code Coverage option in my Scheme's Test section, which suppressed the error but Tests would not run. Then I noticed quite a bit of stuff in NSLog console. Somewhere in there, it mentioned reference to a framework that I was no longer using and trying to load.
我尝试了一堆这些解决方案,但没有运气。我在我的 Scheme 的 Test 部分关闭了 Code Coverage 选项,这抑制了错误但测试不会运行。然后我注意到 NSLog 控制台中有很多东西。在那里的某个地方,它提到了对我不再使用并尝试加载的框架的引用。
I searched the app for it, and Build Settings -> Other Linker Flags was trying to load the framework that wasn't there anymore.
我搜索了该应用程序,并且构建设置 -> 其他链接器标志正在尝试加载不再存在的框架。
I removed: -framework 3rd_party_libname
我删除了:-framework 3rd_party_libname
Then tests worked again. This was confusing, but please check for NSLog msgs. I was using XCode 8.3
然后测试再次起作用。这令人困惑,但请检查 NSLog 消息。我使用的是 XCode 8.3
回答by Pellet
After a long time trying to figure this out, it turned out that I had to create a brand new test target. Then after rebooting the device the problem no longer resurfaced.
经过很长时间的尝试,结果发现我必须创建一个全新的测试目标。然后重新启动设备后,问题不再出现。