Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build an iOS library with Bitcode in order to have backwards compatibility with XCode 6. How?

I am building an iOS static library and I want to provide support for bitcode. In order to achieve that I go to Build settings, search for "custom compiler flags" and add -fembed-bitcode. This builds the library with bitcode and everything works fine under XCode 7.

However by following the approach above I loose backwards compatibility with XCode 6. Having that said I have to ship 2 different library versions to my users, one with bitcode flag and one without since not everyone has upgraded to XCode 7.

Is there a way to have bitcode enabled library and have backwards compatibility without having to ship 2 different versions?

UPDATE:

Hello @Vinicius Jarina thank you for your message. I understand that you can create a fat library which I guess is a common practise. What I was doing so far was to build for both architecture:

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdK iphoneos 
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator

and then call lipo to package in a fat library like:

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"

However, how can i do it now? I tried something like this based on this link, but with no luck:

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" OTHER_CFLAGS='-fembed-bitcode' -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" OTHER_CFLAGS='-fembed-bitcode' -target "${FMK_NAME}" -sdk iphoneos

and then create a fat lib like this:

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"

how can i build in my scipt to include both and then package them in a fat-library?

UPDATE 2:

I finally managed to make this work and I list here my solution for others that may face the same issue:

xcodebuild -configuration "Release" ENABLE_BITCODE=NO -target "${FMK_NAME}" -sdK iphoneos 
xcodebuild -configuration "Release" ENABLE_BITCODE=NO -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" ENABLE_BITCODE=YES -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" ENABLE_BITCODE=YES -target "${FMK_NAME}" -sdk iphoneos

and then create a fat lib like this:

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"
like image 255
andreasv Avatar asked Oct 07 '15 11:10

andreasv


People also ask

What does enable Bitcode do in Xcode?

Enable Bitcode Bitcode is an Apple technology that enables you to recompile your app to reduce its size. The recompilation happens when you upload your app to App Store Connect or export it for Ad Hoc, Development, or Enterprise distribution.

Should I include Bitcode for iOS content?

For iOS apps, bitcode is the default, but optional. If you provide bitcode, all apps and frameworks in the app bundle need to include bitcode. For watchOS apps, bitcode is required.

What is Fembed Bitcode?

-fembed-bitcode [...] fembed-bitcode flag. Given that, if you add the -fembed-bitcode flag to the Other C flags, you will be sending two flags to the compiler during the compile time. It maybe silence some warnings that you can receive when using the library linked on another project.

Is it safe to disable Bitcode?

If you turn BitCode on, then the intermediate representation of the compiled program gets uploaded and Apple will able to recompile and/or optimize your apps for future architectures (as described here). Turning it off is very safe for the time being.


1 Answers

You can try to create a fat-library using different libraries.

lipo -create -output libAndreasv.a libAndreasvBitcode.a libAndreasvARMv7.a libAndreasvARM64.a

This used to work for fat libraries (x86,x64,ARMv7,ARM64) should work for bitcode as well.

like image 193
Vinicius Jarina Avatar answered Oct 14 '22 13:10

Vinicius Jarina