使用Cocoapods将Objective C框架与同一工作区中的多个目标链接起来

时间:2017-07-21 08:25:16

标签: ios cocoapods

我有一个包含多个框架目标和一个应用程序目标的工作区。所有这些目标都依赖于常见的cocoapod(在这种情况下为GoogleMaps)。我应该如何编写我的Podfile,以便所有这些目标都可以使用GoogleMaps而不会在这些目标中重复?

我当前的Podfile如下:

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

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

  # Pods for FrameworkA
  pod 'GoogleMaps'

end

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

  # Pods for FrameworkB

end

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

  # Pods for FrameworkTest

end

这允许我在所有目标中使用GoogleMaps,但最终会在这些目标中重复使用。我可以在控制台中看到这些错误:

Class GMSReverseGeocodeResponse is implemented in both /Users/harshad/Library/Developer/Xcode/DerivedData/FrameworkTest-ccpoenicmupoxyadfsxniyjogcjk/Build/Products/Debug-iphonesimulator/FrameworkA.framework/FrameworkA (0x104b73a30) and /Users/harshad/Library/Developer/Xcode/DerivedData/FrameworkTest-ccpoenicmupoxyadfsxniyjogcjk/Build/Products/Debug-iphonesimulator/FrameworkB.framework/FrameworkB (0x1043b0a30). One of the two will be used. Which one is undefined.

我该如何解决这个问题?

编辑:这是link to the Github project

1 个答案:

答案 0 :(得分:0)

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

def shared_pods
    pod 'GoogleMaps'
end

target 'FrameworkA' do
    shared_pods
end

target 'FrameworkB' do
  shared_pods
end

target 'FrameworkTest' do
    shared_pods
end