xcodebuild 7.3 can't enable bitcode

2019-02-06 06:44发布

问题:

I'm developing an embbeded framework for iOS. In order to make an universal fat (with simulator and device slices), I created an aggregate target with a script that uses xcodebuild and lipo commands to generate it, as many people does.

With XCode 7.x I had to add an user-defined settings with BITCODE_GENERATION_MODE=bitcode in order to enable it, but this has stop working since the last XCode 7.3 release.

I've tried everything I found in the internet like add OTHER_CFLAGS="-fembed-bitcode", but anything works as before...

I have seen this in the build log:

ENABLE_BITCODE is always NO, no matter I do.

Has anybody tried to create an universal fat framework with bitcode enabled using xcodebuild command since XCode 7.3?

回答1:

I ran into a similar issue yesterday. After some investigation, the problem, that appears when running xcodebuild from a "Run Script" build phase in any Xcode target, seems related with the explicit specification of the toolchain to be used, done with the ENV variable TOOLCHAINS.

Therefore, until Apple releases a fixed version of Xcode 7.3, you can try to add the following command at the beginning of your script:

# workaround for bitcode generation problem with Xcode 7.3 unset TOOLCHAINS

This should be harmless, as this env variable is not set by default when you run xcodebuild from the command line, and this workaround works just fine in my case.



回答2:

I'm facing the same issue. Just like you, BITCODE_GENERATION_MODE and OTHER_CFLAGS="-fembed-bitcode" are simply ignored, and my builds broke

I did notice that it sometimes work, and sometimes doesn't. It seems that if you build the framework (or aggreate target) for the simulator, the bitcode goes away, no matter what you have in the xcodebuild commands.

I'm using Xcode 7.3, and I have 2 targets : Static Library, and Aggregate target to make the fat framework.

What works for me when it builds a bitcode-less framework, is to:

  • Select the static library target (not the aggregate one), and pick "Generic iOS device"
  • Clean it
  • Select the static library target, but pick a simulator
  • Build it (works, even if it's instantaneous because it hasn't been cleaned)
  • Select the static library target, but pick "Generic iOS device" again.
  • Build it
  • Select the aggregate target for a "Generic iOS device"
  • Finally, build it
  • If this failed, start over. I sometimes need to do it two or three times before it works.

When I do that, my fat library ends up having bitcode.

You can check that your framework has bitcode support easily by running otool -arch armv7 -l <framework_path> | grep LLVM

In order to break it again, simply build the aggregate target for a simulator. The library will still be a fat one, but bitcode's gone.

Somebody surely can find a solution that works everytime, but at least it fixes the issue for me.

I certainly did not have to do that with Xcode 7.2, and I don't know how that works for pure CLI builds.