在 Podfile 中包含文件

问题描述 投票:0回答:2

我有一个由许多模块组成的应用程序,这些模块使用 cocoapods 链接。链接的模块在运行时被检测到。现在我希望能够从构建服务器添加和删除模块。我现在需要做的是在安装之前删除或添加对 Podfile 的依赖项。

我认为如果我可以将依赖项写入每个目标的单独文件中并将其包含在 Podfile 中,那就太好了。这样我在构建时就不需要修改Podfile。我正在寻找类似 C 语言中的 #include 预处理器指令的东西,但我了解到 ruby 中的 include 和 require 函数的工作方式有很大不同。到目前为止,我最大的成功是尝试

load
,但失败了
Invalid 'Podfile' file: undefined method 'pod' for main:Object.

是否可以包含文件?

ios cocoapods
2个回答
11
投票

不确定这是否受支持,但如果您在模块文件中创建一个从主 Podfile 调用的函数,它确实可以工作。 Podfile:

platform :ios, '9.0'

use_frameworks!

load 'ModulePods.rb'

abstract_target 'CommonPods' do
    module_pods
    pod 'SAMKeychain'

    target 'Target' do
        pod 'RealmSwift
    end
end

ModulePods.rb:

def module_pods
    pod 'ReachabilitySwift', '4.1.0'
end

0
投票

更进一步...

我们有多个组件,它们在所有 Podfile 中都有一些通用代码。因此,我们创建了一个通用的“基本 Podfile”,所有其他 Podfile 都包含该文件。

dir=File.dirname(__FILE__);bpf=File.join(dir, 'BasePodfile.rb');tmp=File.join(dir, 'TempPodfile.rb');
system "if curl -s 'https://raw.github.com/<org>/<project>/0.1.0/BasePodfile.rb' -H 'Authorization: Token <auth token>' > #{tmp} ; then mv #{tmp} #{bpf} ; else rm #{tmp} ; fi"
load "BasePodfile.rb"

只需使用 github 中原始文件的正确路径(或通过类似的托管方法使用)。

然后,将“BasePodfile.rb”扔进你的

.gitignore
,你就处于良好状态了。易于使用常见的 Podfile 功能/更改。

© www.soinside.com 2019 - 2024. All rights reserved.