objective-c XCTest.framework 构建错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18652963/
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-09-03 20:56:53  来源:igfitidea点击:

XCTest.framework build error

iphoneobjective-cxcodebuildframeworks

提问by user2703123

I am using the DropBox Core API in my app and therefore, I must include the XCTest framework, because, when I haven't added the XCTest framework, my app can't connect to dropbox, however when I do add the framework, I get an error while building for the simulator. There is nothing wrong with my code! Here is the error:

我在我的应用程序中使用 DropBox Core API,因此,我必须包含 XCTest 框架,因为当我没有添加 XCTest 框架时,我的应用程序无法连接到 Dropbox,但是当我添加框架时,我为模拟器构建时出错。我的代码没有任何问题!这是错误:

Ld /Users/Zach/Library/Developer/Xcode/DerivedData/SnapDrop!-fchnxyvnqyeefscfhmohrzxtiqeb/Build/Products/Debug-iphonesimulator/SnapDrop!.app/SnapDrop! normal i386
    cd "/Users/Zach/Desktop/SnapDrop!"
    setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
    setenv PATH "/Applications/Xcode5-DP6.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode5-DP6.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode5-DP6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode5-DP6.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/Zach/Library/Developer/Xcode/DerivedData/SnapDrop!-fchnxyvnqyeefscfhmohrzxtiqeb/Build/Products/Debug-iphonesimulator -F/Users/Zach/Library/Developer/Xcode/DerivedData/SnapDrop!-fchnxyvnqyeefscfhmohrzxtiqeb/Build/Products/Debug-iphonesimulator -F/Users/Zach/Downloads/dropbox-ios-sdk-1.3.5 -F/Users/Zach/Downloads/dropbox-ios-sync-sdk-1-1.1.0 -F/Applications/Xcode5-DP6.app/Contents/Developer/Library/Frameworks -F/Users/Zach/Desktop -filelist /Users/Zach/Library/Developer/Xcode/DerivedData/SnapDrop!-fchnxyvnqyeefscfhmohrzxtiqeb/Build/Intermediates/SnapDrop!.build/Debug-iphonesimulator/SnapDrop!.build/Objects-normal/i386/SnapDrop!.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.1 -framework iAd -framework AssetsLibrary -framework QuartzCore -framework SystemConfiguration -framework Security -framework CFNetwork -framework XCTest -framework Dropbox -framework DropboxSDK -framework CoreGraphics -framework UIKit -framework Foundation -Xlinker -dependency_info -Xlinker /Users/Zach/Library/Developer/Xcode/DerivedData/SnapDrop!-fchnxyvnqyeefscfhmohrzxtiqeb/Build/Intermediates/SnapDrop!.build/Debug-iphonesimulator/SnapDrop!.build/Objects-normal/i386/SnapDrop!_dependency_info.dat -o /Users/Zach/Library/Developer/Xcode/DerivedData/SnapDrop!-fchnxyvnqyeefscfhmohrzxtiqeb/Build/Products/Debug-iphonesimulator/SnapDrop!.app/SnapDrop!

ld: building for iOS Simulator, but linking against dylib built for MacOSX file '/Applications/Xcode5-DP6.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest' for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What should I do? If my framework is corrupt, can you tell me how to reinstall it? I have tried deleting and reinstalling Xcode with no luck.

我该怎么办?如果我的框架损坏了,你能告诉我如何重新安装它吗?我尝试删除并重新安装 Xcode,但没有成功。

回答by Ray Fix

I agree with Mike Weller. You should probably not be linking against the XCTest framework in your actual app code. Remove XCTest framework. Look at the linker errors and remove things that are referencing the framework. Wash, rinse, repeat.

我同意迈克·韦勒的观点。您可能不应该在实际应用程序代码中链接 XCTest 框架。删除 XCTest 框架。查看链接器错误并删除引用框架的内容。清洗,冲洗,重复。

If you have a test target, that is different. What can easily happen during the migration from SenTestKit to XCTest is having the wrong framework search path which causes linking against the Mac OS X framework instead of the iOS framework. This doesn't work.

如果你有一个测试目标,那就不同了。在从 SenTestKit 迁移到 XCTest 的过程中很容易发生的情况是框架搜索路径错误,导致链接到 Mac OS X 框架而不是 iOS 框架。这不起作用。

An easy way to see what the correct framework search path settings are is to create a dummy project, open the build settings for the Tests target and then filter for "Framework Search Path."

查看正确的框架搜索路径设置的一种简单方法是创建一个虚拟项目,打开测试目标的构建设置,然后过滤“框架搜索路径”。

I think the correct vanilla paths are:

我认为正确的香草路径是:

$(SDKROOT)/Developer/Library/Frameworks     (non-recursive)
$(inherited)                                (non-recursive)
$(DEVELOPER_FRAMEWORKS_DIR)                 (non-recursive)

回答by Webdevotion

Adding to the possible solutions for this problem:

添加到此问题的可能解决方案:

Make sure you did not include the MyApplicationTests.m file
in the project's non-testing targets "Compile Sources" list.

确保您没有
在项目的非测试目标“编译源”列表中包含 MyApplicationTests.m 文件。

This can happen when you cleaned up folders on the disk
and moved things around manually for example.

例如,当您清理磁盘上的文件夹
并手动移动内容时,就会发生这种情况。

Project > Targets > MyApplication > Build Phases > Compile Sources

The most obvious symptom is that you get the XCTest error
when trying to run your app on the iPhone ( or simulator ).

最明显的症状是当你
尝试在 iPhone(或模拟器)上运行你的应用程序时你得到 XCTest 错误。

XCTest should not be included in your regular application code as stated
in the other answers as well.


其他答案中所述,XCTest 不应包含在您的常规应用程序代码中。

回答by anthoprotic

I Just removed the "XCTest.Framework" file from Project Navigator > Targets > 'Project Name' > Build Phases. Then, "Product" (drop-down) > Clean. Did it for me!

我刚刚从 Project Navigator > Targets > 'Project Name' > Build Phases 中删除了“XCTest.Framework”文件。然后,“产品”(下拉菜单)> 清洁。为我做的!

回答by avuthless

I should add small note:

我应该补充一点:

My project had all paths correct (those three default ones) but the order was different. Setting correct order (by dragging path with mouse in the list) fixed the issue.

我的项目的所有路径都正确(这三个默认路径)但顺序不同。设置正确的顺序(通过在列表中用鼠标拖动路径)解决了这个问题。

回答by Dirty Henry

If you have a test target, you should also make sure that its Base SDKis set to iOS 7.0(or even better: Latest iOS)

如果你有一个测试的目标,你也应该确保其Base SDK设置为iOS 7.0(甚至更好:Latest iOS

回答by brian.clear

Check your Framework Search Paths for your Main target and your test Target. I had a lot of crap in mine

检查您的主要目标和测试目标的框架搜索路径。我有很多废话

easiest if to create a new single view ios project. run the test to see it can run - by default it fails then check the Framework Searhc Path in main and test targets. and compare it to you project

最简单的方法是创建一个新的单视图 ios 项目。运行测试以查看它可以运行 - 默认情况下它会失败,然后检查主目标和测试目标中的框架搜索路径。并将其与您的项目进行比较

see answer by me brian.clear here

在这里看到我的回答 brian.clear

Apple Mach-O linker (id) warning : building for MacOSX, but linking against dylib built for iOS

Apple Mach-O 链接器 (id) 警告:为 MacOSX 构建,但链接为为 iOS 构建的 dylib

回答by karim

None of the above works for me, I still get the error,

以上都不适合我,我仍然收到错误,

ld: warning: Auto-Linking supplied '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest', missing required architecture i386 in file /Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest (2 slices)

ld:警告:自动链接提供了“/Applications/Xcode.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest”,文件 /Applications/Xcode.app/Contents/Developer/Library/ 中缺少所需的架构 i386 Frameworks/XCTest.framework/XCTest(2 个切片)

I used the refactor option of XCode 6, converted my properly running SenTests to XCTests.

我使用了 XCode 6 的重构选项,将我正确运行的 SenTests 转换为 XCTests。

However when I set the framework search paths to ,

但是,当我将框架搜索路径设置为

$(SDKROOT)/Developer/Library/Frameworks and 
$(inherited)

it worked.

有效。

回答by Prakash Raj

You Can create your framework project, which is going to be a pod project without test files. Simple uncheck the tests while creating the project.

您可以创建您的框架项目,这将是一个没有测试文件的 pod 项目。在创建项目时简单地取消选中测试。

回答by Mohd Haider

This can be a reason:

这可能是一个原因:

If you have linked XCTest framework in both targets "MyApplication" and "MyApplicationTests". Then we do need to import "MyApplication" in "MyApplicationTests" file as

如果您在两个目标“MyApplication”和“MyApplicationTests”中都链接了 XCTest 框架。然后我们确实需要在“MyApplicationTests”文件中导入“MyApplication”作为

@testable import FlickrDemo

So it will create cyclic import and will cause XCTest framework not found issue. Simple solution will be to remove XCTest framework from "MyApplication" target.

所以它会创建循环导入并导致 XCTest 框架未找到问题。简单的解决方案是从“MyApplication”目标中删除 XCTest 框架。

Hope this will help someone.

希望这会帮助某人。