63

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.

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

Edit: Originally only disabled it for one of the targets. Once I disabled all of them and I was able to build successfully.

4

9 回答 9

173

要以一种不会在每次执行时都被覆盖的方式设置此设置,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
于 2015-09-20T23:40:51.413 回答
7

有一种方法可以使用完整的位码构建 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

我认为这种方式比禁用位码更好。

于 2016-03-23T09:34:38.797 回答
5
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
于 2017-08-28T20:12:18.760 回答
5

要为您自己的开发 pod 禁用位码,只需在项目的 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
于 2019-01-17T11:25:37.220 回答
2

如果您可以控制 .podspec(即使用自己的规范/git repo 提供 pod)

s.pod_target_xcconfig = { 'ENABLE_BITCODE' => '否' }

于 2021-10-13T08:51:45.743 回答
2

在主项目和 Pod 中禁用 Bitcode

其他答案无法清除主项目的位码标志。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 阶段

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
于 2018-10-04T11:52:16.757 回答
2

除了@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
于 2020-11-19T23:23:16.957 回答
1

如果您启用了多个 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
于 2019-06-05T13:53:41.173 回答
-3

转到您希望禁用它的目标的构建设置。搜索显示“启用比特码”的内容,将其设置为否。

于 2015-09-17T21:25:22.453 回答