问题描述
我的项目有9个目标:
- Prod
- Prod_app_extension_1
- Prod_app_extension_2
- Beta
- Beta_app_extension_1
- Beta_app_extension_2
- Dev
- Dev_app_extension_2
- Dev_app_extension_2
我正在使用0.38.2 cocoapod版本和2.5.4 AFNetworking。
I'm using 0.38.2 cocoapod version and 2.5.4 AFNetworking.
我正在尝试将AFNetworking与cocoapod,但编译时出现 AF_APP_EXTENSIONS 错误。在网上搜索解决方案后,我了解了问题所在,并发现定义预处理程序宏 AF_APP_EXTENSIONS 可以解决此问题。
I'm trying to use AFNetworking with cocoapod but I get the AF_APP_EXTENSIONS error while compiling. After searching for the solution on the web, I understand the problem and found that defining the 'preprocessor macros' AF_APP_EXTENSIONS can fix the problem.
但这是一个难题:默认情况下, AF_APP_EXTENSIONS 已正确添加到我的6个app_extensions中。另一方面,当我浏览Pods目标时,每个Pod都分开了:
But here is the struggle : By default, AF_APP_EXTENSIONS is correctly added into my 6 app_extensions. In the other hand, when I navigate through my Pods target, each Pods are separated :
- NSDate+TimeAgo
- AFNetworking
- iRate
- AppUtils
- Prod
- Prod_app_extension_1
- Prod_app_extension_2
- Beta
- Beta_app_extension_1
- Beta_app_extension_2
- Dev
- Dev_app_extension_2
- Dev_app_extension_2
在我做的另一个项目中,所有豆荚都是这样生成的:
In another project I made, all pods are generated this way :
- Prod
- Pods-Prod-NSDate+TimeAgo
- Pods-Prod-AFNetworking
- Pods-Prod-iRate
- Pods-Prod-AppUtils
- Prod_app_extension_1
- Pods-Prod_app_extension_1-NSDate+TimeAgo
- Pods-Prod_app_extension_1-AFNetworking
- Pods-Prod_app_extension_1-iRate
- Prod_app_extension_2
- Pods-Prod_app_extension_2-NSDate+TimeAgo
- Pods-Prod_app_extension_2-AFNetworking
- Pods-Prod_app_extension_2-iRate
- Beta
- Pods-Beta-NSDate+TimeAgo
- Pods-Beta-AFNetworking
- Pods-Beta-iRate
- Pods-Beta-AppUtils
- Beta_app_extension_1
- Pods-Beta_app_extension_1-NSDate+TimeAgo
- Pods-Beta_app_extension_1-AFNetworking
- Pods-Beta_app_extension_1-iRate
- Beta_app_extension_2
- Pods-Beta_app_extension_2-NSDate+TimeAgo
- Pods-Beta_app_extension_2-AFNetworking
- Pods-Beta_app_extension_2-iRate
- Dev
- Pods-Dev-NSDate+TimeAgo
- Pods-Dev-AFNetworking
- Pods-Dev-iRate
- Pods-Dev-AppUtils
- Dev_app_extension_1
- Pods-Dev_app_extension_1-NSDate+TimeAgo
- Pods-Dev_app_extension_1-AFNetworking
- Pods-Dev_app_extension_1-iRate
- Dev_app_extension_2
- Pods-Dev_app_extension_2-NSDate+TimeAgo
- Pods-Dev_app_extension_2-AFNetworking
- Pods-Dev_app_extension_2-iRate
我认为这就是为什么我的预处理器宏 AF_APP_EXTENSIONS 不是定义到 AFNetworking广告连播目标中。
I think this is why my 'preprocessor macros' AF_APP_EXTENSIONS isn't define into the 'AFNetworking' Pods target.
这是我的Podfile:
Here is my Podfile :
platform :ios, '7.0'
xcodeproj 'myProj.xcodeproj'
def generic_pods
pod 'NSDate+TimeAgo'
pod 'AFNetworking', '~> 2.0'
end
def app_pods
pod 'iRate'
pod 'AppUtils',
end
target "Prod" do
generic_pods
app_pods
end
target "Prod_app_extension_1" do
generic_pods
end
target "Prod_app_extension_2" do
generic_pods
end
target "Beta" do
generic_pods
app_pods
end
target "Beta_app_extension_1" do
generic_pods
end
target "Beta_app_extension_2" do
generic_pods
end
target "Dev" do
generic_pods
app_pods
end
target "Dev_app_extension_1" do
generic_pods
end
target "Dev_app_extension_2" do
generic_pods
end
不知道是什么问题,这让我发疯。
I don't know what the problem is, and it's driving me crazy.
推荐答案
因为cocoapod版本为0.38.0,所以pod目标已被重复删除。这意味着,不是为每个项目目标( Pods-MyApp-AFNetworking, Pods-MyExtension-AFNetworking ...)构建一个AFNetworking,而是仅生成一个AFNetworking Pod目标( Pods-AFNetworking)。
Since 0.38.0 cocoapod version, pod target are De-duplicate. It means, instead of bulding an AFNetworking for each of your project target ('Pods-MyApp-AFNetworking', 'Pods-MyExtension-AFNetworking', ...) only one AFNetworking pod target is generated ('Pods-AFNetworking').
AFNetworking要求将'AF_APP_EXTENSIONS'标志添加到GCC_PREPROCESSOR_DEFINITIONS 中,以便在添加到应用扩展名时进行编译。
AFNetworking require 'AF_APP_EXTENSIONS' flag into the GCC_PREPROCESSOR_DEFINITIONS to compile when added to app-extensions.
直到0.37.2 cocoapod版本,可以通过添加安装后例程从项目Podfile中添加标志:
Until the 0.37.2 cocoapod version, it was possible to add the flag from your project Podfile by adding a post-install routine :
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if ar.include? target.name
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
end
end
end
end
不幸的是,使用去重复cocoapod功能,不再可以向应用程序添加AF_APP_EXTENSIONS标志扩展Pod分别针对目标。
Unfortunatly, with the De-duplicate cocoapod feature, it's no longer possible to add the AF_APP_EXTENSIONS flag to the app extention pod targets separately.
我发现唯一的编译方法是创建一个文件:〜/ .. cocoapods / config.yaml (使用cocoapod时默认情况下不存在,您可以在终端上使用以下内容创建它:
The only way I found is to compile is to create a file : ~/.cocoapods/config.yaml (not present by default when you use cocoapod, you can create it with the terminal) with this content :
deduplicate_targets: false
这样,不会对Pod进行重复数据删除,您可以在安装后将AF_APP_EXTENSIONS添加到您的应用中扩展名GCC_PREPROCESSOR_DEFINITIONS。
This way, pods aren't not de-duplicated and you can post-install add the AF_APP_EXTENSIONS into your app extensions GCC_PREPROCESSOR_DEFINITIONS.
我只是希望他们能找到防止此问题的好方法。
I just hope they will found a good way to prevent this problem.
引用:
=> cocoapod更改日志
https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#highlighted-enhancement-that-needs-testing => cocoapod change log
=>讨论过的问题
这篇关于Cocoapod 0.38.0和AFNetworking 2.5 AF_APP_EXTENSIONS编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!