CocoaPods-应用程序和框架共享依赖项时重复的符号

时间:2019-04-03 20:18:22

标签: ios swift cocoapods crashlytics

我正在编写一个iOS应用程序,使用CocoaPods 1.6.0作为我的依赖项管理器。我的项目包括一个iOS应用程序项目(myapp-ui)和3个iOS框架项目(myapp-commonmyapp-modelmyapp-editor)。我还利用Fabric.io进行崩溃报告和应用指标。我的myapp-uimyapp-model项目都使用FabricCrashlytics框架。我的Pods文件如下所示:

platform :ios, '11.0'
workspace 'MyApp.xcworkspace'

project 'myapp-ui/myapp-ui.xcodeproj'
project 'myapp-common/myapp-common.xcodeproj'
project 'myapp-model/myapp-model.xcodeproj'
project 'myapp-editor/myapp-editor.xcodeproj'

target 'myapp-ui' do
  use_frameworks!

  project 'myapp-ui/myapp-ui.xcodeproj'

  # Pods for myapp-ui
  pod 'SwiftyBeaver'
  pod 'SwifterSwift'
  pod 'Fabric'
  pod 'Crashlytics'
  pod 'KeychainSwift', '~> 13.0'

  target 'myapp-uiTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

target 'myapp-common' do
  use_frameworks!

  project 'myapp-common/myapp-common.xcodeproj'

  # Pods for myapp-common
  pod 'SwiftyBeaver'
  pod 'SwifterSwift'
  pod 'KeychainSwift', '~> 13.0'

end

target 'myapp-model' do
  use_frameworks!

  project 'myapp-model/myapp-model.xcodeproj'

  # Pods for myapp-model
  pod 'SwiftyBeaver'
  pod 'SwifterSwift'
  pod 'Fabric'
  pod 'Crashlytics'

end

target 'myapp-editor' do
  use_frameworks!

  project 'myapp-editor/myapp-editor.xcodeproj'

  # Pods for myapp-editor

end

吊舱安装得很好,并且我的应用程序构建没有问题。但是,当我运行它时,我在控制台中看到大量类似以下内容的错误:

objc[62607]: Class CLSInternalReport is implemented in both <SOME LOCATION>/Build/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252f960) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f2831e8). One of the two will be used. Which one is undefined.
objc[62607]: Class Crashlytics is implemented in both <SOME LOCATION>/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252f9b0) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f283238). One of the two will be used. Which one is undefined.
objc[62607]: Class CLSFileManager is implemented in both <SOME LOCATION>/Build/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252fa00) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f283288). One of the two will be used. Which one is undefined.
objc[62607]: Class CLSAlert is implemented in both <SOME LOCATION>/Build/Products/Debug-iphonesimulator/myapp_model.framework/myapp_model (0x11252fa78) and <SOME OTHER LOCATION>/myapp-ui.app/myapp-ui (0x10f283300). One of the two will be used. Which one is undefined.

是否有解决这些警告的方法?我曾尝试将它们从myapp-ui中删除,以为myapp-ui使用了myapp-model(因此会继承依赖项),但这没有用。我不知如何解决这个问题。有想法吗?

1 个答案:

答案 0 :(得分:1)

我收到与您所看到的相同的警告,花了我一段时间才找到解决办法。事实证明,当您具有预先编译的依赖项(例如FabricCrashlytics)时,会发生这种情况。我认为是因为它们被复制了两次。

我所做的是仅将这些Pod添加到应用程序目标中。我的Podfile最终看起来像这样

def pods
    pod 'CGMath'
    ...
end

def app
    pod 'Crashlytics'
    pod 'Fabric'
end

target 'FrameworkTarget' do
    pods
end

target 'AppTarget' do
    pods
    app
end