在主要目标中包含 pod,而不是在 WatchKit 扩展中

Posted

技术标签:

【中文标题】在主要目标中包含 pod,而不是在 WatchKit 扩展中【英文标题】:Include pods in main target and not in WatchKit extension 【发布时间】:2015-03-28 19:53:34 【问题描述】:

我在当前项目中添加了一个 WatchKit 扩展。该项目使用 Cocoapods 0.36.1 添加一些框架,但现在我想从 WatchKit 扩展项目中排除一些 pod。

WatchKit 扩展项目不需要我在正常目标中使用的很多框架,但是在更改我的 Podfile 后,我无法让 Cocoapods 正常工作。

我在 Podfile 中使用 use_frameworks!,但在运行 pod install 后,我收到以下消息:

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `HomeHandler` to `Pods/Target Support Files/Pods-HomeHandler/Pods-HomeHandler.debug.xcconfig` or include the `Pods/Target Support Files/Pods-HomeHandler/Pods-HomeHandler.debug.xcconfig` in your build configuration.
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `HomeHandler` to `Pods/Target Support Files/Pods-HomeHandler/Pods-HomeHandler.release.xcconfig` or include the `Pods/Target Support Files/Pods-HomeHandler/Pods-HomeHandler.release.xcconfig` in your build configuration.
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `HomeHandler WatchKit Extension` to `Pods/Target Support Files/Pods-HomeHandler WatchKit Extension/Pods-HomeHandler WatchKit Extension.debug.xcconfig` or include the `Pods/Target Support Files/Pods-HomeHandler WatchKit Extension/Pods-HomeHandler WatchKit Extension.debug.xcconfig` in your build configuration.
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `HomeHandler WatchKit Extension` to `Pods/Target Support Files/Pods-HomeHandler WatchKit Extension/Pods-HomeHandler WatchKit Extension.release.xcconfig` or include the `Pods/Target Support Files/Pods-HomeHandler WatchKit Extension/Pods-HomeHandler WatchKit Extension.release.xcconfig` in your build configuration.

我没有更改基本配置的任何设置,但我的 3 个目标中有 2 个设置了正确的 Pods.debugPods.release。没有基本配置的是 WatchKit App

我原来的 Podfile

platform :ios, '8.0'
use_frameworks!

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git'
pod 'CocoaLumberjack', '~> 2.0.0'
pod 'MagicalRecord', :git => "https://github.com/magicalpanda/MagicalRecord.git"
pod 'PureLayout'
pod 'UAProgressView'
pod 'UICKeyChainStore'
pod 'XLForm', git: 'git@github.com:xmartlabs/XLForm.git'
pod 'Classy', git: 'git@github.com:depl0y/Classy.git'
pod 'Reveal-iOS-SDK', :configurations => ['Debug']
pod 'JBChartView', '~> 2.8.9'
pod 'RFQuiltLayout'
pod 'HUMSlider', '~> 1.0'
pod 'SwiftEventBus', :git => 'https://github.com/cesarferreira/SwiftEventBus.git'

post_install do |installer_representation|
    installer_representation.project.targets.each do |target|
        if target.name == "Pods-AFNetworking"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'AF_APP_EXTENSIONS=1']
            end
        end
        if target.name == "Pods-PureLayout"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'PURELAYOUT_APP_EXTENSIONS=1']
            end
        end
    end
end

我修改后的 Podfile

这是我想从我的 WatchKit 项目中排除某些 pod 的地方。

platform :ios, '8.0'

use_frameworks!

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

link_with "HomeHandler", "HomeHandler WatchKit Extension"

pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git'
pod 'CocoaLumberjack', '~> 2.0.0'
pod 'MagicalRecord', :git => "https://github.com/magicalpanda/MagicalRecord.git"

pod 'UICKeyChainStore'

target :HomeHandler do
    pod 'XLForm', git: 'git@github.com:xmartlabs/XLForm.git'
    pod 'UAProgressView'
    pod 'Classy', git: 'git@github.com:depl0y/Classy.git'
    pod 'Reveal-iOS-SDK', :configurations => ['Debug']
    pod 'JBChartView', '~> 2.8.9'
    pod 'RFQuiltLayout'
    pod 'HUMSlider', '~> 1.0'
    pod 'SwiftEventBus', :git => 'https://github.com/depl0y/SwiftEventBus.git'
    pod 'PureLayout'
end

post_install do |installer_representation|
    installer_representation.project.targets.each do |target|
        if target.name == "Pods-AFNetworking"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'AF_APP_EXTENSIONS=1']
            end
        end
        if target.name == "Pods-PureLayout"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['$(inherited)', 'PURELAYOUT_APP_EXTENSIONS=1']
            end
        end
    end
end

【问题讨论】:

【参考方案1】:

CocoaPods 输出的警告是由于两个 CocoaPods 目标试图链接到您的应用程序中的单个目标(不支持)。

即,您有一个明确的目标 HomeHandler 并且您也将无名目标链接到 HomeHandler 与 link_with "HomeHandler", "HomeHandler WatchKit Extension"

我的建议是将您的 Podfile 修改为如下所示:

platform :ios, '8.0'
use_frameworks!

source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'

def shared_pods
    pod 'AFNetworking', :git => 'https://github.com/AFNetworking/AFNetworking.git'
    pod 'CocoaLumberjack', '~> 2.0.0'
    pod 'MagicalRecord', :git => "https://github.com/magicalpanda/MagicalRecord.git"
    pod 'UICKeyChainStore'
end

target 'HomeHandler' do
    shared_pods
    pod 'XLForm', git: 'git@github.com:xmartlabs/XLForm.git'
    pod 'UAProgressView'
    pod 'Classy', git: 'git@github.com:depl0y/Classy.git'
    pod 'Reveal-iOS-SDK', :configurations => ['Debug']
    pod 'JBChartView', '~> 2.8.9'
    pod 'RFQuiltLayout'
    pod 'HUMSlider', '~> 1.0'
    pod 'SwiftEventBus', :git => 'https://github.com/depl0y/SwiftEventBus.git'
    pod 'PureLayout'
end

target 'HomeHandler WatchKit Extension' do
    shared_pods
end

【讨论】:

我收到此错误:找不到 -lPods-Project_name WatchKit Extension 的库。我的 pod 文件是: # 取消注释此行以为您的项目定义一个全局平台 # platform :ios, '8.0' # 如果您使用 Swift,请取消注释此行 # use_frameworks! platform :ios, :deployment_target => “7.0” target 'Project_name' , :exclusive => true do pod 'Google/Analytics' end target 'Project_name WatchKit Extension' do pod 'Google/Analytics' end target 'Project_name WatchKit App' do pod 'Google/Analytics' end @kylef 这在 xcode 8 下对我不起作用。它安装得很好,没有问题,但是当我编译项目时,有数千个与应用扩展中包含的 pod 相关的错误,即使它们不包含在扩展的target do end 块。

以上是关于在主要目标中包含 pod,而不是在 WatchKit 扩展中的主要内容,如果未能解决你的问题,请参考以下文章

我如何在我的 .exe 中包含批处理文件而不是在 .exe 所在的文件夹中需要它们

如何在单独的 js 文件中使用访问 django 模板变量,而不是在同一个 html 文件中包含小脚本块?

编译 pod 时“在框架模块中包含非模块化标头”

在 Swift 项目中包含 SQLCipher pod 时如何避免构建错误?

Cocoapods:将 pod 链接到多个目标问题

在 swift 框架项目中包含 CocoasMQTT 库