简体   繁体   English

将Carthage支持添加到现有项目中

[英]Adding Carthage Support to an Existing Project

I've forked the AEXML project and I'm trying add Carthage support. 我已经分叉了AEXML项目,我正在尝试添加Carthage支持。 I've added a framework target and a created a new Scheme that is marked as shared (see screenshots below). 我添加了一个框架目标,并创建了一个标记为共享的新Scheme(参见下面的屏幕截图)。 I am able to run carthage build and in my Carthage/Build/iOS I see: 我可以运行carthage build ,在我的Carthage/Build/iOS我看到:

在此输入图像描述

When dragging the resulting AEXML.framework file into my example application the project will build however upon launching I receive: 将生成的AEXML.framework文件拖放到我的示例应用程序中时,项目将在启动时生成,但是我会收到:

在此输入图像描述

I feel that I've messed up along the way somewhere but I'm not exactly sure how to go about fixing this. 我觉得我已经在某个地方搞砸了但是我不确定如何解决这个问题。

在此输入图像描述

You should add run script at your example project's "Build Phase", like: 您应该在示例项目的“构建阶段”中添加运行脚本,如:

On your application targets' “Build Phases” settings tab, click the “+” icon and > choose “New Run Script Phase”. 在应用程序目标的“构建阶段”设置选项卡上,单击“+”图标,然后选择“新建运行脚本阶段”。 Create a Run Script with the following contents: 使用以下内容创建运行脚本:

 /usr/local/bin/carthage copy-frameworks

and then add the paths to the frameworks you would like to use under “Input Files”, eg: 然后将路径添加到要在“输入文件”下使用的框架,例如:

 $(SRCROOT)/Carthage/Build/iOS/Box.framework
 $(SRCROOT)/Carthage/Build/iOS/Result.framework
 $(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework

I had tried to do this by myself by adding to the script to check if each framework was found in the BUILD_PRODUCTS_DIR and then recursively copying them, if not. 我曾尝试通过添加脚本来检查是否在BUILD_PRODUCTS_DIR中找到每个框架然后以递归方式复制它们(如果没有)。 When that didn't work, I ended up with this linking issue: 当这不起作用时,我最终得到了这个链接问题:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest Referenced from: .../build/Products/Debug-iphonesimulator/Specta.framework/Specta Reason: image not found dyld:未加载库:@ rpath / XCTest.framework / XCTest引用自:... / build / Products / Debug-iphonesimulator / Specta.framework / Specta原因:未找到图像

I finally tried creating the copy files phase and included my frameworks and dSYMs, creating groups, then moved all these to the Frameworks group in Xcode 7.2. 我终于尝试创建复制文件阶段并包含我的框架和dSYM,创建组,然后将所有这些移动到Xcode 7.2中的Frameworks组。 My linking issues were completely gone. 我的链接问题完全消失了。

The error you have points that framework binary was not found at runtime. 你得到的错误指出在运行时没有找到框架二进制文件。 Answer by Abner Zhong will work in most cases, but sometimes you have to try harder (for me it was unit tests target). Abner Zhong的回答在大多数情况下会有效,但有时你必须更加努力(对我而言,这是单元测试的目标)。 To make it work Carthage README suggests: 为了使其工作, Carthage README建议:

In rare cases, you may want to also copy each dependency into the build product (eg, to embed dependencies within the outer framework, or make sure dependencies are present in a test bundle). 在极少数情况下,您可能还希望将每个依赖项复制到构建产品中(例如,在外部框架中嵌入依赖项,或确保测试包中存在依赖项)。 To do this, create a new “Copy Files” build phase with the “Frameworks” destination, then add the framework reference there as well. 为此,使用“Frameworks”目标创建一个新的“Copy Files”构建阶段,然后在那里添加框架引用。

You can do this here: 你可以在这里这样做: Xcode目标设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM