Disable bitcode for project and cocoapods dependencies with Xcode 7?

IosCocoapodsBitcode

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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.

Solution 3 - Ios

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

Solution 4 - Ios

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

Solution 5 - Ios

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

Solution 6 - Ios

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

Solution 7 - Ios

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

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

Solution 8 - Ios

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

Solution 9 - Ios

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjhergView Question on Stackoverflow
Solution 1 - IosKeith SmileyView Answer on Stackoverflow
Solution 2 - IoswerediverView Answer on Stackoverflow
Solution 3 - IosRomulo RegoView Answer on Stackoverflow
Solution 4 - IosRajesh KumarView Answer on Stackoverflow
Solution 5 - IosCarterView Answer on Stackoverflow
Solution 6 - IosCameron Lowell PalmerView Answer on Stackoverflow
Solution 7 - IosErkki Nokso-KoivistoView Answer on Stackoverflow
Solution 8 - IosYuriy PavlyshakView Answer on Stackoverflow
Solution 9 - IosKris GellciView Answer on Stackoverflow