使用Xcode7禁用项目和cocoapods依赖项的bitcode?

jhe*_*erg 54 ios cocoapods bitcode

如何为项目和cocoapod依赖项禁用bitcode?这是我在尝试使用Xcode 7运行项目时遇到的错误.

不包含bitcode.您必须在启用bitcode(Xcode设置ENABLE_BITCODE)的情况下重建它,从供应商处获取更新的库,或禁用此目标的bitcode.对于架构arm64

编辑:最初只为其中一个目标禁用它.一旦我禁用了所有这些,我就能够成功构建.

Kei*_*ley 146

要以每次执行时都不会被覆盖的方式设置此设置,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
Run Code Online (Sandbox Code Playgroud)

  • @BillNoto这将仅在Pods上运行,而不在主项目上运行 (2认同)

wer*_*ver 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
Run Code Online (Sandbox Code Playgroud)

我认为这种方法比禁用bitcode更好.

  • @cberkay因为bitcode是由Apple专门介绍的,它提供了更好的用户体验,减少了安装时间和尺寸. (3认同)
  • 为什么这种方式更好? (2认同)
  • 位代码减少安装时间和大小?不,App Thinning 实现了这一点,它与多架构二进制文件完美配合。Bitcode 的优势并不明显,取决于苹果想要实现的长期目标。在 watchOS 这样的平台上,指令调整可以产生显着的性能优势,其优势更为明显。 (2认同)
  • @Mario不幸的是,不可能将Bitcode嵌入到预构建的库中(据我所知,“libProj4.a”不是从源代码构建的)。位码通常是从源代码生成的,机器代码是从位码生成的,但反之则不然。 (2认同)

Raj*_*mar 6

要为您自己的开发 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
Run Code Online (Sandbox Code Playgroud)


Rom*_*ego 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
Run Code Online (Sandbox Code Playgroud)


小智 5

除了@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
Run Code Online (Sandbox Code Playgroud)


nox*_*oxo 5

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

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