ios – 如何使用CocoaPods与多个Framework子项目

首先,我已经打开了use_framework!在Podfile.

假设主项目是MAIN_APP,两个子项目是FRAMEWORK_A和FRAMEWORK_B.

MAIN_APP需要FRAMEWORK_A和FRAMEWORK_B,FRAMEWORK_B也需要FRAMEWORK_A.

所有项目/目标都使用CocoaPods来管理第三方库.

现在,我的Podfile看起来像:

target :MAIN_APP do
    project 'MAIN_APP'
    pod 'PodA'
end

target :FRAMEWORK_A do
    project 'FRAMEWORK_A'
    pod 'PodB'
end

target :FRAMEWORK_B do
    project 'FRAMEWORK_B'
    pod 'PodC'
end

我手动添加了FRAMEWORK_A来构建FRAMEWORK_B的设置,以及FRAMEWORK_A和FRAMEWORK_B两者来构建MAIN_APP的设置.

所有代码编译都很好,但是当运行MAIN_APP崩溃,因为它无法加载Framework的PodB.

我知道我可以手动将PodB添加到MAIN_APP和FRAMEWORK_B,但是可以在Podfile中定义这种目标依赖关系吗?

Btw,pod安装时,我收到警告:

[!] The Podfile contains framework targets,for which the Podfile does not contain host targets (targets which embed the framework).

If this project is for doing framework development,you can ignore this message. Otherwise,add a target to the Podfile that embeds these frameworks to make this message go away (e.g. a test target).

据我所知,我可以使用嵌套目标为主机目标,如:

target :FRAMEWORK_A
    target :MAIN_APP
    end
end

所以CocoaPods将设置MAIN_APP使用FRAMEWORK_A并继承来自FRAMEWORK_A的pod依赖.但是似乎我不能像多个依赖关系那样做:

target :FRAMEWORK_A
    target :MAIN_APP
    end
end
target :FRAMEWORK_B
    target :MAIN_APP
    end
end

因为target:MAIN_APP不能被声明两次.

有没有更好的解决方案,而不是将pod依赖项定义为Podfile中的一个功能,并包含在所有目标中?

解决方法

这是一个很好的问题,我也遇到了类似的情况.这是我的PodFile:
platform :ios,'8.0'

workspace 'mygreatapp.xcworkspace'

project 'app/MyGreatApp/MyGreatApp.xcodeproj'
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'

abstract_target 'This can say whatever you want' do

    target 'MyGreatApp' do
        project 'app/MyGreatApp/MyGreatApp.xcodeproj'
        pod 'AFNetworking','~> 2.6.0'
        pod 'PromiseKit','~> 1.5'
        pod 'PromiseKit/Join'
        pod 'KVOController','~> 1.0'
        pod 'FLAnimatedImage','~> 1.0'
        pod 'Crashlytics','~> 3.3'
        pod 'SSZipArchive'
    end

    target 'MyGreatAppTests' do
        project 'app/MyGreatApp/MyGreatApp.xcodeproj'
        pod 'OCMock','~> 3.1'
    end

    target 'MyGreatFramework' do
        project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
        pod 'SSZipArchive'
    end

    target 'MyGreatFrameworkTests' do
        project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
        pod 'OCMock','~> 3.1'
    end

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['ENABLE_BITCODE'] = 'NO'
        end
      end
    end
end

正如你可以看到我没有使用框架,我使用一个abstract_target来将它们组合在一起.我希望这些依赖关系在CocoaPods中更容易做到.我知道这不是真的回答你的问题,但它可能是有益的.

以上是来客网为你收集整理的ios – 如何使用CocoaPods与多个Framework子项目全部内容,希望文章能够帮你解决ios – 如何使用CocoaPods与多个Framework子项目所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。