使用 Xcode 7 禁用项目和 cocoapods 依赖项的位码?
Disable bitcode for project and cocoapods dependencies 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
编辑:最初只对其中一个目标禁用它。一旦我禁用了所有这些,我就能够成功构建。
转到要禁用它的目标的构建设置。搜索显示 "Enable Bitcode" 的内容,将其设置为 No.
要以每次执行 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
有一种方法可以使用完整的位码构建 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
我认为这种方式比禁用位码更好。
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
在主项目中禁用 Bitcode 和 Pods
其他答案未能清除主项目的位码标志。 Cocoapod 的 Post-Install hooks 不让你访问主项目,我相信这是设计选择,所以你需要找到项目文件并使用 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阶段
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
只为你自己的开发 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
cocoapods 1.7+ 更新(如果您启用了多个 xcodeproj 生成):
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
除了@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
如果您可以控制 .podspec(即使用自己的规范/git 存储库提供 pod)
s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' }
如何禁用项目和 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
编辑:最初只对其中一个目标禁用它。一旦我禁用了所有这些,我就能够成功构建。
转到要禁用它的目标的构建设置。搜索显示 "Enable Bitcode" 的内容,将其设置为 No.
要以每次执行 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
有一种方法可以使用完整的位码构建 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
我认为这种方式比禁用位码更好。
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
在主项目中禁用 Bitcode 和 Pods
其他答案未能清除主项目的位码标志。 Cocoapod 的 Post-Install hooks 不让你访问主项目,我相信这是设计选择,所以你需要找到项目文件并使用 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阶段
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
只为你自己的开发 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
cocoapods 1.7+ 更新(如果您启用了多个 xcodeproj 生成):
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
除了@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
如果您可以控制 .podspec(即使用自己的规范/git 存储库提供 pod)
s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' }