ios 使用 Xcode 7 禁用项目和 cocoapods 依赖项的位码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32640149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable bitcode for project and cocoapods dependencies with Xcode 7?
提问by jherg
How can you disable bitcode for your project and cocoapod dependencies? Here is the error I get when trying to run my project with Xcode 7.
如何禁用项目和 cocoapod 依赖项的位码?这是我尝试使用 Xcode 7 运行我的项目时遇到的错误。
does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64
不包含位码。您必须在启用位码的情况下重建它(Xcode 设置 ENABLE_BITCODE),从供应商处获取更新的库,或为此目标禁用位码。用于架构 arm64
Edit: Originally only disabled it for one of the targets. Once I disabled all of them and I was able to build successfully.
编辑:最初仅针对其中一个目标禁用它。一旦我禁用了所有这些,我就能够成功构建。
回答by Keith Smiley
To set this setting in a way that doesn't get overridden each time you do a pod install
you can add this to your Podfile
要以每次执行时都不会被覆盖的方式设置此设置,pod install
您可以将其添加到您的Podfile
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
回答by werediver
There is a way to build CocoaPods' targets with full bitcode. Just add -fembed-bitcode
option to OTHER_CFLAGS
of each:
有一种方法可以使用完整的位代码构建 CocoaPods 的目标。只需为每个添加-fembed-bitcode
选项OTHER_CFLAGS
:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
cflags = config.build_settings['OTHER_CFLAGS'] || ['$(inherited)']
cflags << '-fembed-bitcode'
config.build_settings['OTHER_CFLAGS'] = cflags
end
end
end
I think this way is better than disabling bitcode.
我认为这种方式比禁用位码更好。
回答by Romulo Rego
project 'frameworkTest.xcodeproj'
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
target 'frameworkTest' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for frameworkTest
source 'https://github.com/CocoaPods/Specs.git'
#zip files libs
pod 'SSZipArchive'
#reachability
pod 'Reachability'
end
#bitcode enable
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# set valid architecture
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s i386 x86_64'
# build active architecture only (Debug build all)
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['ENABLE_BITCODE'] = 'YES'
if config.name == 'Release' || config.name == 'Pro'
config.build_settings['BITCODE_GENERATION_MODE'] = 'bitcode'
else # Debug
config.build_settings['BITCODE_GENERATION_MODE'] = 'marker'
end
cflags = config.build_settings['OTHER_CFLAGS'] || ['$(inherited)']
if config.name == 'Release' || config.name == 'Pro'
cflags << '-fembed-bitcode'
else # Debug
cflags << '-fembed-bitcode-marker'
end
config.build_settings['OTHER_CFLAGS'] = cflags
end
end
end
回答by Cameron Lowell Palmer
Disabling Bitcode in Main Project and Pods
在主项目和 Pod 中禁用 Bitcode
The other answers fail to clear out the bitcode flag for the main project. The Post-Install hooks of the Cocoapod do not give you access to the main project, I believe this is design choice, so you need to find the project file and modify it using xcodeproj. If a binary library includes bitcode you will need to use xcrun bitcode_strip
to remove the bitcode to make the project consistent.
其他答案未能清除主项目的位码标志。Cocoapod 的 Post-Install hooks 不能让你访问主项目,我相信这是设计选择,所以你需要找到项目文件并使用xcodeproj修改它。如果二进制库包含位代码,您将需要使用xcrun bitcode_strip
来删除位代码以使项目保持一致。
Two helper functions
两个辅助函数
def disable_bitcode_for_target(target)
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
remove_cflags_matching(config.build_settings, ['-fembed-bitcode', '-fembed-bitcode-marker'])
end
end
def remove_cflags_matching(build_settings, cflags)
existing_cflags = build_settings['OTHER_CFLAGS']
removed_cflags = []
if !existing_cflags.nil?
cflags.each do |cflag|
existing_cflags.delete_if { |existing_cflag| existing_cflag == cflag && removed_cflags << cflag }
end
end
if removed_cflags.length > 0
build_settings['OTHER_CFLAGS'] = existing_cflags
end
end
Post_install phase
安装后阶段
post_install do |installer|
project_name = Dir.glob("*.xcodeproj").first
project = Xcodeproj::Project.open(project_name)
project.targets.each do |target|
disable_bitcode_for_target(target)
end
project.save
installer.pods_project.targets.each do |target|
disable_bitcode_for_target(target)
end
installer.pods_project.save
end
回答by Rajesh Kumar
For disable bitcode for your own development pod only add this below code in pod file of the projects.
要为您自己的开发 pod 禁用 bitcode,只需在项目的 pod 文件中添加以下代码。
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "YOUR SDK TARGET NAME"
puts "Processing for disable bit code in YOUR SDK TARGET NAME SDK"
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
end
回答by Yuriy Pavlyshak
Update for cocoapods 1.7+ if you have enabled multiple xcodeproj generation:
如果您启用了多个 xcodeproj 生成,则更新 cocoapods 1.7+:
install! 'cocoapods', :generate_multiple_pod_projects => true
<Pod list section>
post_install do |installer|
installer.pod_target_subprojects.each do |subproject|
subproject.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
end
回答by Kris Gellci
Go to the build settings for the target you wish to disable it on. Search for something that says "Enable Bitcode", set it to No.
转到要禁用它的目标的构建设置。搜索显示“启用位码”的内容,将其设置为“否”。