用Carthage嵌套我自己的框架 [英] Nesting My Own Frameworks with Carthage

查看:102
本文介绍了用Carthage嵌套我自己的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试由我开发的两个框架和一个应用程序之间实现以下依赖关系设置时遇到问题:

I'm having problems trying to realize the following dependency setup between two frameworks and an app, all developed by me:


  1. 实用程序包含许多低级实用程序和对<$ c的扩展$ c> Foundation 类型,例如 String Date 等。

  1. Util containts a bunch of low-level utilities and extensions to Foundation types such as String, Date, etc.

UI 包含一堆自定义的 UIView UIViewController 子类, UIColor UIImage 的类扩展,等等。

UI contains a bunch of custom UIView and UIViewController subclasses, class extensions for UIColor, UIImage, etc..

该应用程序和每个框架在GitHub上都有自己的存储库。

The app and each framework has its own repository on GitHub.

UI 框架已设置为使用迦太基依赖于 Util 框架:

The UI framework is set up to depend on the Util framework, using Carthage:


  1. 项目的 Cartfile 包含对 Util 回购的引用:

github MyOrganization / Util.git

实用程序列在链接的框架和库中,但未嵌入(因为 UI 是一个框架项目,不是应用)。

Util is listed in "Linked Frameworks and Libraries", but not embedded (because UI is a framework project, not an app).

框架搜索路径构建设置除 $(继承) $(PROJECT_DIR)/ Carthage / Build / iOS >

The Framework Search Paths build setting contains $(PROJECT_DIR)/Carthage/Build/iOS in addition to $(inherited)

.gitignore文件配置为忽略整个 Carthage 目录(不仅仅是 / Build

The .gitignore file is configured to ignore the whole Carthage directory (not just /Build)

使用git子模块,但我没有打算(我已经有足够的头痛了。)

I am not using git submodules, and I don't intend to (I have enough headaches already).






如果我克隆UI框架并运行 carthage update ,Carthage获取/构建Util,我可以手动将其嵌入以构建UI框架。


If I clone the UI framework and run carthage update, Carthage fetches/builds Util and I can embed it manually to build the UI framework.

到目前为止很好。

但是,如果我克隆 App 框架并运行 carthage更新,则Carthage将获取 UI 回购,但无法构建:

But if I clone the App framework and run carthage update, Carthage fetches the UI repo, but it fails to build:


  1. 目录 App / Carthage / Checkouts 包含UI项目的签出副本,与预期的一样。但是,嵌套框架没有更多的Carthage目录(我认为它应该是 App / Carthage / Checkouts / UI / Carhage / Checkout / Util )。

  1. The directory App/Carthage/Checkouts contains the checked-out copy of the UI project, as expected. However, there is no further Carthage directory for the nested framework (I assume it should be App/Carthage/Checkouts/UI/Carhage/Checkout/Util).

导航到 App / Carthage / Checkouts / UI 使用Xcode在此处打开工作区并构建它也显然失败。对 Util.framework 的引用已损坏。

Navigating to App/Carthage/Checkouts/UI opening the workspace there with Xcode and building it also fails, obviously. The reference to Util.framework is broken.

根据我的阅读,迦太基应该获取递归依赖;我在这里缺少什么?

From what I've read, Carthage should fetch the recursive dependency; What am I missing here?

我尝试将两个框架URL添加到 App Cartfile中,但是xcode仍然无法构建 UI 框架。

I tried adding both framework URLs the the App Cartfile, but xcode still fails to build the UI framework.

迦太基输出指向的日志底部显示:

The bottom part of the log pointed to by the carthage output says:

/Users/me/Projects/App/code/App/Carthage/Checkouts/UI/code/UI/UI/MyClass.swift:10:8: error: no such module 'Util'

import Util
       ^

** ARCHIVE FAILED **


The following build commands failed:
    CompileSwift normal arm64
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)






更新



我将最小可复制示例(在GitHub上)。应用程序和框架组成了此依赖关系图:


Update

I put together a minimal reproducible example on GitHub. The app and frameworks make up this dependency graph:

A -> B -> C
// (and also A -> C, but that's not relevant now)

(C是应用程序,B和C是框架)。

(C is the app, B and C are frameworks).

上运行迦太基更新时> A 项目,它同时获取两个框架存储库,签出两个框架存储库,首先构建 B 并失败,就像上面那样( import

When running carthage update on the A project, it fetches both framework repos, checks out both, starts to build B first and fails, just as above (import directive).

已检出的 B 副本具有正确的Cartfile以及所有源文件,但没有嵌套的 Carthage / 目录,更不用说其中的 C 副本了。

The checked out copy of B has the right Cartfile, along with all the source files, but there is no nested Carthage/ directory, let alone the necessary copy of C within it.

我想我需要以某种方式使构建过程引用 A / Carthage / Builds / C.framework A / Carthage / Checkouts / B / Carthage / Builds / C.framework 的内容,但不知道如何设置B项目以解决此问题...

I guess I need to somehow make the build process refer to A/Carthage/Builds/C.framework instead of A/Carthage/Checkouts/B/Carthage/Builds/C.framework, but don't know how to set up the B project for that to work out...

推荐答案

TL,DR:我的UI框架的根目录中没有Cartfile。存储库,因此迦太基无法在构建过程中看到它(即使文件本身已被提取,并且存储了更深的目录)。

TL, DR: My UI framework didn't have its Cartfile at the root of the repository, so carthage could not "see" it during the build (even though the file itself was fetched, and stored several directories deeper).

作为Github用户 Sho Ikeda @ikesyo )指出迦太基存储库的这个线程/问题,我是中级框架(在本例中为 UI )的根目录中没有其 Cartfile 。相反,它更像是这样:

As Github user Sho Ikeda (@ikesyo) kindly pointed out on this thread/issue of the Carthage repository, my intermediate framework (UI, in this case) didn't have its Cartfile at the root. Instead, it was more like this:

.git
.gitignore
docs/
code/
    UI.workspace
    UI/
        UI.xcodeproj
        Cartfile
        Carthage/
            Build/
            Checkouts/

等,

.git
.gitignore
Cartfile
docs/
code/
    UI.workspace
    UI/
        UI.xcodeproj

Carthage/
    Build/
    Checkouts/

我假设Cartfile必须与Xcode项目处于同一级别。事实并非如此。将Cartfile移到根目录后,并从以下位置更改我的框架项目的构建设置框架搜索路径:

I was under the assumption that the Cartfile had to be at the same level as the Xcode project; that is not the case. After moving the Cartfile to the root, and changing my framework project's Build Setting "Framework Search Paths" from:

$(PROJECT_DIR)/Carthage/Build/iOS

至:

$(PROJECT_DIR)/../../Carthage/Build/iOS

...为了说明移动,以便在从其工作区构建 UI.frame 时链接到 Util 不会失败。

...in order to account for the move, so that linking against Util when building UI.framework from its workspace doesn't fail.

最后,我在 App 目录中运行了迦太基更新 ,如Carthage GitHub页面中所述,链接了框架等,它的工作原理很吸引人。我可以从应用程序的源代码(最外部)成功实例化在Util(最内部)框架中定义的类。

Lastly, I ran carthage update form my App directory, linked the frameworks, etc. as explained in the Carthage GitHub page, and it worked like a charm. I can successfully instantiate classes defined in my Util (innermost) framework from my App's source code (outermost).

这篇关于用Carthage嵌套我自己的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆