问题
My team recently started to employ CocoaPods to manage dependency in our iOS app project.
Here's the podfile:
platform :ios, '6.0'
pod "UI7Kit"
pod "AFNetworking", "~> 2.0"
pod "TMCache"
pod "SVProgressHUD"
pod "SVPullToRefresh"
However, after using CocoaPods, building targets for iPhone 5 always fails, but succeeds for simulator.
Here's the error log:
ld: warning: ignoring file [DerivedData directory]/libPods.a, file was built for archive which is not the architecture being linked (armv7): [DerivedData directory]/libPods.a
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_SVProgressHUD", referenced from:
objc-class-ref in ....o
"_OBJC_CLASS_$_TMCache", referenced from:
objc-class-ref in ....o
"_OBJC_CLASS_$_UI7Kit", referenced from:
objc-class-ref in ....o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've tried solutions mentioned in CocoaPods Troubleshooting, including adding the Pods
static library on top of the list, but it still fails.
Later we found that in "Pods Project Settings" > "Build Settings" > "Architectures", "Base SDK" is set as "No SDK (Latest OS X)", "Build Active Architecture Only" > "Debug" set as "Yes" and "Supported Platforms" set as "OS X". After changing them to "Latest iOS (iOS 7.0)", "No", "iOS" respectively, building for iPhone 5 and simulator both work fine.
However, each time we do Pod update
, all of the three settings are reverted to their previous states, which is annoying.
My questions are:
- Is this case by design or something is wrong with my project/workspace setting?
- How to prevent these settings from being reverted to the wrong states?
Any help will be appreciated.
回答1:
As mentioned in CocoaPods issues, you can append this to your Podfile:
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
end
end
end
This will make all pods build for all arch.
回答2:
I found myself running into this situation as well, using Cocoapods 0.36.3 and Xcode 6.2. I highly doubt that this is the best solution, but I wrote a hook to go at the bottom of my Podfile that resets the "BaseSDK", "Platform", and "Build Active Architecture Only" settings in the Pods project. I also set "Build Active Architecture Only" to "NO" for each of the targets, for good measure (as mentioned in the above post).
post_install do |installer_representation|
projectSDK = nil
puts"Updating all of the POD targets to not default to ONLY_ACTIVE_ARCH for debug"
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
if projectSDK.nil?
projectSDK = config.build_settings['SDKROOT']
end
end
end
puts "Updating ONLY_ACTIVE_ARCH for the project, as well. While the project settings aren't supposed to matter, I've not found that to be the case."
puts "Also setting the base SDK of the project to match that of the targets (doesn't matter which one); otherwise it defaults to No SDK (Latest OS X)"
installer_representation.project.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['SDKROOT'] = projectSDK
end
end
回答3:
For anyone using latest Cocoa pods
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
end
end
end
回答4:
I used to follow that procedure... now with cocoapods and more hours into the matter I opted for :
# fixes required for xcode project
post_install do |installer_representation|
puts ""
puts "Updating VALID_ARCHS, SUPPORTED_PLATFORMS, SDKROOT for the project..."
installer_representation.pods_project.build_configurations.each do |config|
# config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s'
config.build_settings['SUPPORTED_PLATFORMS'] = 'iphonesimulator iphoneos'
# setting the base SDK of the project to match that of the project,
# otherwise it defaults to No SDK (Latest OS X)"
config.build_settings['SDKROOT'] = 'iphoneos'
# it sets 'Valid Architectures' to '$(ARCHS_STANDARD)' to all pods
# config.build_settings['SDKROOT'] = projectSDK
end
puts ""
puts "Updating all of the watch POD targets with specific..."
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if (config.build_settings['SDKROOT'] == 'watchos')
puts "fixing SUPPORTED_PLATFORMS & VALID_ARCHS for #{target.name} #{config.name}"
config.build_settings['SUPPORTED_PLATFORMS'] = 'watchsimulator watchos'
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s armv7k i386'
end
# to not default to ONLY_ACTIVE_ARCH for debug"
# config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
# config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = "NO"
end
end
puts ""
end
回答5:
The Pods Project settings don't matter, what is important are the Target settings for the Pod static lib. But you shouldn't have to touch them.
Can you post your build settings from your project/target?
The Troubleshooting guide suggests some build settings in case of failed build, do they help? Be sure to enable to show all build settings and check if some settings override those specified in the xcconfig
file that CocoaPods generated.

Also check that your project is based on the xcconfig
file in in the project's Info tab.

I hope something of this helps.
来源:https://stackoverflow.com/questions/20464183/supported-platforms-base-sdk-build-active-architecture-only-settings-reverted