Enable Bitcode in library file (.a)

After enabling bit code in Xcode 7, I couldn’t build .a file with embed-bitcode. Same problem for the zbar library, too. So, I cannot use my own library with a .a file or cannot use the zbar for production. After searching from google, I found a way to build. We need to use the command line with xcodebuild.

I wrote the build.sh like following and same folder with myproject.xcodeproj


xcodebuild OTHER_CFLAGS="-fembed-bitcode" -target $project_name build
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -sdk iphonesimulator -target $project_name build
rm -r build/Production-SDK
cp -r build/$folder-iphoneos build/Production-SDK
cp build/$folder-iphonesimulator/$lib_name.a build/Production-SDK/$name_simulator.a
mv build/Production-SDK/$lib_name.a build/Production-SDK/$name_device.a
cd build/Production-SDK/
lipo -create $name_simulator.a $name_device.a -output $lib_name.a
rm $name_device.a
rm $name_simulator.a
file $lib_name.a
open .

In the build.sh , folder is your release folder name. zbar is using Distribution-iphoneos and Distribution-iphonesimulator .

If you using your own, it may be Release-iphoneos and Release-iphonesimulatorlib_name is your .a library name. In Zbar, it’s using libzbar . project_name is your traget to build. Sometime , lib_name and project_name is different in the project.

After chasing this two, you can run in terminal like

sh ./build.sh

Need to wait until finishing the build and then it will show your lib.a file. In the terminal, you can check, it’s showing what platform is supporting.

If it doesn’t support i386,x86_64,armv7, arm64, you need to open your project. Go to Build Settings -> Valid Architectures. Add all architectures like following

  • armv7
  • armv7s
  • i386
  • arm64
  • x86_64

Don’t forget to change Build Active Architecture Only to NO

Gravatar Image
My name is Than Dana but I’d like to be called Dana. I’m 28 years old and a single man. I’m from Toungoo, Bago division. I live in Yangon for my job and work as Digital Marketing Executive @ Win Mobile World Co., Ltd. I stand as a professional in IT fields and have been sharing, inventing and advancing tech developments since about 2008.