如何为项目和cocoapod依赖项禁用bitcode?这是我在尝试使用Xcode 7运行项目时遇到的错误。
不包含bitcode。您必须在启用bitcode(Xcode设置ENABLE_BITCODE)的情况下重建它,从供应商处获取更新的库,或禁用此目标的bitcode。 for architecture arm64
编辑:最初只为其中一个目标禁用它。一旦我禁用所有这些并且我能够成功构建。
答案 0 :(得分:138)
要设置此设置,每次执行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
答案 1 :(得分:8)
有一种方法可以用完整的bitcode构建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
我认为这种方式比禁用bitcode更好。
答案 2 :(得分:4)
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
答案 3 :(得分:1)
转到要禁用它的目标的构建设置。搜索“启用Bitcode”的内容,将其设置为No。
答案 4 :(得分:1)
其他答案无法清除主项目的位码标志。 Cocoapod的Post-Install钩子无法让您访问主项目,我相信这是设计选择,因此您需要找到项目文件并使用xcodeproj对其进行修改。如果二进制库包含位代码,则需要使用xcrun bitcode_strip
删除位代码以使项目一致。
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 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
答案 5 :(得分:1)
仅针对您自己的开发平台禁用位码 将此代码添加到项目的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
答案 6 :(得分:0)
如果已启用多个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
答案 7 :(得分:0)
除了@werediver的答案:
如果要启用位代码,建议在post_install
中设置['ENABLE_BITCODE'] = 'YES'
。您还可以添加部署目标(以防止XCode抱怨)。在这种情况下:['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
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
config.build_settings['ENABLE_BITCODE'] = 'YES'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
end