Podfile中一个target内的目标

7

我正在尝试将Google移动广告SDK安装到我的Xcode项目中。我已经安装了Cocoapods,然后在我的项目中初始化了一个Podfile:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'

target 'Cubical' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Cubical

  target 'CubicalTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'CubicalUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

然而,我不明白为什么我的主项目(Cubical)中会有目标。我从来没有真正使用过CubicalTests或CubicalUITests,因为我不需要测试我的界面或任何代码片段。我考虑删除这两个文件夹。

我的问题是:

1)从我的Xcode项目中删除Tests和UITests文件夹是否有任何缺点?如果我这样做,我是否可以简单地从Podfile中删除这两个目标?

2)假设我要保留这两个目标。我是否需要将pod添加到所有三个目标中?还是两个嵌套的目标继承了'Cubical'目标的所有pods?

3)我需要将Google Mobile Ads SDK添加到链接的框架中吗?还是Cocoapods已经完成了这项工作?

我的最终pod如下所示:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.2'

target 'Cubical' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  pod 'Google-Mobile-Ads-SDK'

  # Pods for Cubical

  target 'CubicalTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'CubicalUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end
1个回答

10

问题1:

如果您不需要执行这种类型的测试,删除TestsCubicalUITests目标和文件夹时没有任何问题。

问题2::

您可以像下面这样与多个目标共享pods:

def shared
pod 'Google-Mobile-Ads-SDK'
end

target 'Target1' do
shared
end

target 'Terget2' do
shared
end

多目标全局Pods

#Global Pod for all targets
pod 'Google-Mobile-Ads-SDK'

target 'target1' do
    pod 'Fabric' #Pod for nested Target. i.e., Google-Mobile-Ads-SDK + Fabric
end

target 'target2' do
 pod 'RadioButton'#Pod for nested Target. i.e., Google-Mobile-Ads-SDK + RadioButton
end

嵌套目标的Pods:

#Global Pod for all targets
pod 'Google-Mobile-Ads-SDK'

target 'target1' do
   pod 'RadioButton' #Available for target1 and target2
   target 'target2 copy' do 
      pod 'Fabric' #Available for target2 only
   end
end

问题3:

链接的框架是由cocoapods自动完成的。请参见此处,您需要使用没有cocoapods的框架来链接该框架。


非常棒的答案,但是嵌套目标和全局目标有什么区别呢?(如果这是正确的术语的话,我对Ruby并不熟悉) - Pablo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接