I am trying to build a new bitcode-enabled tvOS framework whose details are as follows:
Language used in Framework: Swift 3.0
Type of Library: XYZ.framework
Is it a Universal build (supporting both Simulator and Device)?: YES
tvOS Deployment Target: 9.2 onwards
I am building the framework from a script using xcodebuild command as per the following steps:
1. Making a device build using the following command in script.
xcodebuild -target "${FRAMEWORK_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -arch arm64 ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" -sdk appletvos
2. Making a Simulator build using the following command in script.
xcodebuild -target "${FRAMEWORK_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -arch x86_64 ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode-marker" -sdk appletvsimulator
3. Making a Universal build using the following lipo command
lipo -create -output "${UNIVERSAL_FRAMEWORK}/${FRAMEWORK_NAME}" "${CONFIG_DEVICE_DIR}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${CONFIG_SIMULATOR_DIR}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
All the above 3 commands are executed successfully and an Universal framework is being built without any issues. But, when I try to verify if the final framework is bitcode enabled or not using the following commands, I am not getting any results.
otool -l tvOSFramework.framework/tvOSFramework | grep __bitcode (or)
otool -l tvOSFramework.framework/tvOSFramework | grep __LLVM
When I try to include this framework in an application and try to archive the application (AppName: TestAppObjC written in Obj C) using XCode, archiving fails with the following error:
Failed to verify bitcode in tvOSFramework.framework/tvOSFramework:
error: Cannot extract bundle from /var/folders/9f/9sgckkbn7xx61p6m25kh80kc0000gn/T/IDEDistributionThinningStep.XFm/Payload/TestAppObjC.app/Frameworks/tvOSFramework.framework/tvOSFramework (x86_64)
I had tried with setting BITCODE_GENERATION_MODE=bitcode also but the same issue occurs.
Hence, I finally ended up in having two different versions of the framework one for device and one for the Simulator. But I would like to have an Universal framework instead with bitcode enabled.
Can anybody let me know if there is a way to arrive at a bitcode enabled Universal Swift framework for tvOS?
There are a few important details to consider:
- Distributing Swift frameworks that are built for later inclusion in an app is not supported, and is documented in the Xcode 8.0 release notes. You should setup your app project to build the framework as a dependency of the app target instead. See Technical Note 2435, Embedding Frameworks In An App for how to setup a project like this.
- Universal frameworks that cover both a device and a simulator are not supported. You should build two frameworks instead, one for the device OS, the other for the simulator, as you say you are doing.
- If this was an Objective-C framework, you would need to do either an archive or an install build from xcodebuild to generate a build product that includes bitcode. When doing one of these build types, the only build setting that matters is the Enable Bitcode build setting on the framework target. See the man page for xcodebuild to see how to specifcy either an install or an archive build action.