Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i make fat framework with bitcode option?

Tags:

xcode

ios

bitcode

Environment: XCode 7.0.1 Module: Objective-C Bundle Type: Framework

Hi, I am trying to create a framework to support armv7, armv7s, arm64, i386 and x86_64. I am using aggregate to make the fat library. Inside the aggregate script, i am running two xcodebuild commands 1. for armv7, armv7s and arm64 and 2. for i386 and x86_64 architectures. Also, I have set Enable Bitcode=YES and Other C Flags=-fembed-bitcode under target build settings. As a precautionary mesasure, i am adding ENABLE_BITCODE=YES and OTHER_CFLAGS="-fembed-bitcode" options to the xcodebuild command

My xcode build commands are as follows -

#Build The framework Target for iPhoneOS
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${AN_TARGET}" 
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphoneos 
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" 
CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}" SYMROOT="${SYMROOT}" 
ARCHS="armv7 armv7s arm64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION

#Build The framework Target for iPhoneSimulator
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${AN_TARGET}" 
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphonesimulator 
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" 
CONFIGURATION_BUILD_DIR="${IPHONE_SIMULATOR_BUILD_DIR}" SYMROOT="${SYMROOT}" 
ARCHS="i386 x86_64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION

after running the above two commands, i am combining these two builds to make a fat framework binary using the below command

# create a fat Framework
lipo -create 
"${IPHONE_DEVICE_BUILD_DIR}/${PROJECT_NAME}.framework/${PROJECT_NAME}" 
"${IPHONE_SIMULATOR_BUILD_DIR}/${PROJECT_NAME}.framework/${PROJECT_NAME}" -
output "${FRAMEWORK_FOLDER}/${AN_END_USER_FRAMEWORK_NAME}"

The issue iam facing is after the lipo is created, i am unable to use it in the bitcode enabled application. After running the otool -l framework_binary | grep -LLVM, i do not see the bitcode enabled flags or __LLVM.

Lipo removes bitcode from the fat binary. Is there a way i can retain bitcode while running the lipo command?

Correction: Based on the reply from Nestor, i ran the otool command as otool -l -arch armv7 framework_binary | grep LLVM and much to my surprise, i could see the segname __LLVM clang. However when i integrate the same fat framework binary into my project, it builds fine on simulator however throws the following error while running on device - ld: 'MyBinary' 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 armv7

like image 292
Deepak Badiger Avatar asked Oct 13 '15 15:10

Deepak Badiger


People also ask

Where is enable Bitcode in XCode?

When building an application with XCode, we have an option to set the Enable Bitcode flag to either YES or NO via Build Settings > Build Options.

What is Bitcode enabled app?

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.

What is disabling Bitcode?

Bitcode-enabled builds In 2015, Apple added the option to embed bitcode into applications compiled with Xcode. When this option is disabled, the compiler generates an executable file that only contains machine code.


1 Answers

Happily it's just a problem with otool's reporting, not lipo; you have to add the -arch parameter:

otool -arch arm64 -l myLipoOutput.a

Source: http://www.openradar.me/radar?id=6301306440384512

like image 173
Nestor Avatar answered Oct 29 '22 04:10

Nestor