Compiling iOS library with bitcode enabled

I need to release a framework with bitcode enabled which turns out as a hassle. I set ‘Enable Bitcode’ in the project’s settings to ‘YES’ and it builds cleanly for both a real device and a simulator.

I wanted to test the library so I integrated it to a new app I created for this purpose but now it only build for simulators. When I try to build for a real device I get:

  • Getting Twitter handle from Twitter Framework in iOS
  • Share cocoapods with custom framework included in project
  • Swift debugger does not show variable values when importing ObjC framework
  • What is the procedure for installing an external framework or library for Swift in XCode 6?
  • Undefined symbols for architecture armv7: “_SCNetworkReachabilityCreateWithAddress”
  • What does ENABLE_BITCODE do in xcode 7?
  • ld: '/path/to/Framework.framework/Company(File.o)' 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
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Like I said, I had built it with Bitcode enabled so I’m not sure why this happens.

    Any ideas? thanks

    2 Solutions Collect From Internet About “Compiling iOS library with bitcode enabled”

    AFAIK, when you build app with Xcode it includes Bitcode only when you make archive, the reason – decrease compile time when just want to debug or test the app/library.

    To ensure that Xcode emits bitcode at each build you can add -fembed-bitcode flag to Other C flags and Other linker flags:

    enter image description here

    enter image description here

    Also, the easiest way to check if the binary contains bitcode is to use otool and grep:

    otool -l binary_name | grep __LLVM

    you will see one or more segname __LLVM entries if it does have bitcode or empty output if does not.

    Another way with RunScript code: (build setting — Build Phases RunScript)
    enter image description here

    # define output folder environment variable
    # Step 1. Build Device and Simulator versions
    xcodebuild -target TARGETNAME ONLY_ACTIVE_ARCH=NO -configuration Release -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
    xcodebuild -target TARGETNAME -configuration Release -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
    # make sure the output directory exists
    # Step 2. Create universal binary file using lipo
    lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"
    # Last touch. copy the header files. Just for convenience
    cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"