9

I'm encountering a build error when I set 'Enable Bitcode' to 'YES' in the build settings of a project I'm currently working on. The error is:

ld: bitcode bundle could not be generated because '/Users/nick/Library/Developer/Xcode/DerivedData/PROJECTNAME-esksqmlmtpqewpbktcqeqloackeu/Build/Intermediates.noindex/PROJECT.build/Debug-iphoneos/PROJECTNAME.build/Objects-normal/arm64/main.o' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build file '/Users/nick/Library/Developer/Xcode/DerivedData/PROJECTNAME-esksqmlmtpqewpbktcqeqloackeu/Build/Intermediates.noindex/PROJECT.build/Debug-iphoneos/PROJECTNAME.build/Objects-normal/arm64/main.o' for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

(I've redacted the project name to PROJECTNAME and a variant to PROJECT to post here.)

At first I though it could be due to one of the dependencies this project is using via Cocoapods but they all have 'Enable Bitcode' set to 'YES' and I'd expect to see the name of the offending library in the error message if that was the case. The project uses no frameworks other than those included via Cocoapods (and Apple frameworks).

I've tried deleting the derived data, restarting Xcode as well as clearing the build folder but the error persists.

I've also tried the '-fembed-bitcode-marker' solution as suggested for a similar problem here:

iOS library to BitCode

But I'm not building a static library but an app so perhaps unsurprising it made no difference.

The project is fairly large and has been developed since 2012 so includes Objective-C and Swift. It currently has iOS 8 as deployment target and 11.2 as base SDK. It's never had Bitcode enabled in any dev or production version in the past. We've got Bitcode enabled on similar but more recent projects. We're currently using Xcode 9.2 (9C40b).

I know I could set 'Enable Bitcode' to 'NO' for the project's build settings to 'fix' the error but I'd rather have bitcode enabled for the re-optimisations Apple can do once the binary is uploaded as mentioned here: Apple Docs - App Thinning

Am I missing a flag in the build settings that fixes this error or perhaps something else? Any advice is much appreciated!

Many thanks, Nick

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Nick Daly
  • 308
  • 4
  • 13

1 Answers1

14

After updating to Xcode 10 we tried to generate a Bitcode bundle again for this project and (after trying different build configs) have been able to do so. The config that eventually worked for this project was:

For the Project's and Pod's Build Settings:

  • 'Enable Bitcode' set to 'YES'
  • Adding '-fembed-bitcode' to 'Other C Flags'
  • Adding 'BITCODE_GENERATION_MODE' with the value 'bitcode'

These settings were needed for Debug as well as Release. This is because Debug would throw the 'bitcode could not be generated' error (see original question) if we tried to use the '-fembed-bitcode-marker' or 'marker' flags.

We'd have preferred to use the 'marker' variants for Debug as it's quicker to compile but at least we now have something that works!

Nick Daly
  • 308
  • 4
  • 13
  • 1
    Adding the `BITCODE_GENERATION_MODE` piece was the fix for me for my own static framework embedded in my xcode 10.2 project in 2019. THANK YOU – Mike Aug 28 '19 at 12:14
  • 3
    @Mike can you please tell where you would add the BITCODE_GENERATION_MODE? – Hari Narayanan Sep 23 '19 at 14:12
  • I am added this "BITCODE_GENERATION_MODE" but I cannot able to delete this user settings can you please how I should remove it.! – Hari Narayanan Sep 23 '19 at 14:58
  • Added BITCODE_GENERATION_MODE and it's working now, I am not sure why this setting is not mentioned anywhere. – Dinesh Kachhot Aug 17 '20 at 11:01
  • Well, nothing else was working but your solution saved the day. I was setting it to marker (debug) and bitcode (release) but still it wasn't working. Another step I had to do was to uncheck the Bitcode checkbox while creating the IPA. Without that, the IPA processing was failing. Thanks a lot for your suggestion! – AJ7 Apr 22 '21 at 09:36