ChatGPT解决这个技术问题 Extra ChatGPT

Disable bitcode for project and cocoapods dependencies with Xcode 7?

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.

possible duplicate of New warnings in iOS9

K
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

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

Working perfect
I did this but also had to disable bitcode in my project’s build settings. Neither alone fixed this for me.
@BillNoto this will only operate on the Pods, not on the main project
w
werediver

There is a way to build CocoaPods' targets with full bitcode. Just add -fembed-bitcode option to OTHER_CFLAGS of each:

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.


Why is this way better?
@cberkay Because bitcode was introduced by Apple on purpose and provides better user experience reducing the installation time and size.
Bitcode reducing installation time and size? No, App Thinning achieves that, which works perfectly well with multi-architecture binaries. The advantages of Bitcode are murky and depend on what Apple wants to achieve long-term. The advantages on a platform like watchOS, where instruction tweaking could yield significant performance benefits, are a bit more obvious.
Any idea how to dig down into a target? Specifically, I'm using an old version of MapBox, which relies on Proj4. (MapBox contains Proj4.) Xcode complains about the libProj4.a library needing the bitcode set. The above ruby code doesn't embed the bitcode into the Proj4 library (which does not show up as one of the targets.each targets). What I want is something like: target.projects_included_in_the_target.each do |subtarget|. Then, I could find the Proj4 and embed the bitcode there, too. Any ideas? Thanks!
@Mario Unfortunately, it's not possible to embed Bitcode into a prebuilt library (as I understand libProj4.a is not built from sources). Bitcode is normally generated from source code and machine code is generated from Bitcode, but not vice versa.
R
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

I put in the pod file. This script set the xcode’s bitcode flags.
Can you please send me the screenshot of your framework's podfile?
I changed the answer and put full podfile.
R
Rajesh Kumar

For disable bitcode for your own development pod only add this below code in pod file of the projects.

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

C
Carter

In addition to @werediver's answer:

If you want to enable bitcode, In your post_install I suggest setting ['ENABLE_BITCODE'] = 'YES'. You can also add your deployment target (to stop XCode from complaining). In this case: ['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

C
Cameron Lowell Palmer

Disabling Bitcode in Main Project and Pods

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.

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

This is a complete version, thx, It can update main project's build_settings.
Y
Yuriy Pavlyshak

Update for cocoapods 1.7+ if you have enabled multiple xcodeproj generation:

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

E
Erkki Nokso-Koivisto

If you have control over .podspec (i.e providing the pod using own specs / git repo)

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


K
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.


Thanks! Originally only disabled it for one of the targets. Once I disabled all of them and I was able to build.
A problem with this answer is that if you re-run pod install you'll lose the setting. It's not a good long-term solution.

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now