Is it possible to create a universal iOS infrastructure using bit code?

From what I understand, bitcode allows you to create binary files with an intermediate binary format. So this is a step before compiling the ARM or x64 architecture.

You can create a β€œreal” .framework file for iOS with iOS 8. However, frame files are compiled for only one architecture by default (emulator, iPhone). When someone wants to distribute a .framework file, it is best to provide a file compatible with the iOS emulator, as well as for deployment on iPhone. You can find various sample scripts for creating such a thick file using lipo .

However, would it be possible to distribute only .framework compiled as a bitcode without having to create a file with different architectures?

Unfortunately, even with bit code for my .framework :

  • different files are created by default according to the target architecture
  • even if the archive menu appears to be enabled for the target environment, I cannot find the result even in my Organizer view

Am I misunderstanding something in the concept of bit code, or am I missing something?

+7
ios xcode bitcode
source share
1 answer

You need to provide a universal flat base. What is created by lipo .

  • Enable Bitcode, Targets->Build Setting->Enable Bitcode - Yes
  • Add assembly target to create a universal structure

    Create an Aggregate target and copy the following script command into Build Phrase -> Run Script :

     ########################
     # Options
     ########################

     #verbose
     set -x

     REVEAL_ARCHIVE_IN_FINDER = false

     FRAMEWORK_NAME = "$ {PROJECT_NAME}"

     SIMULATOR_LIBRARY_PATH = "$ {BUILD_DIR} / $ {CONFIGURATION} -iphonesimulator / $ {FRAMEWORK_NAME} .framework"

     DEVICE_LIBRARY_PATH = "$ {BUILD_DIR} / $ {CONFIGURATION} -iphoneos / $ {FRAMEWORK_NAME} .framework"

     UNIVERSAL_LIBRARY_DIR = "$ {BUILD_DIR} / $ {CONFIGURATION} -iphoneuniversal"

     FRAMEWORK = "$ {UNIVERSAL_LIBRARY_DIR} / $ {FRAMEWORK_NAME} .framework"


     ########################
     # Build Frameworks
     ########################
     # Build for simulator
     xcodebuild -target $ {PROJECT_NAME} -sdk iphonesimulator -configuration $ {CONFIGURATION} ARCHS = "i386 x86_64" ONLY_ACTIVE_ARCH = NO clean build CONFIGURATION_BUILD_DIR = $ {BUILD_DIR} / $ {CONFIGURATION} -iphonesim
     # Build for device
     xcodebuild -scheme $ {PROJECT_NAME} -sdk iphoneos -configuration $ {CONFIGURATION} ARCHS = "armv7 armv7s arm64" ONLY_ACTIVE_ARCH = NO clean archive CONFIGURATION_BUILD_DIR = $ {BUILD_DIR} / $ {CONFIGURATION} -iphoneos

     ########################
     # Create directory for universal
     ########################

     rm -rf "$ {UNIVERSAL_LIBRARY_DIR}"

     mkdir "$ {UNIVERSAL_LIBRARY_DIR}"

     mkdir "$ {FRAMEWORK}"


     ########################
     # Copy files Framework
     ########################

     cp -r "$ {DEVICE_LIBRARY_PATH} /."  "$ {FRAMEWORK}"


     ########################
     # Make an universal binary
     ########################

     lipo "$ {SIMULATOR_LIBRARY_PATH} / $ {FRAMEWORK_NAME}" $ {DEVICE_LIBRARY_PATH} / $ {FRAMEWORK_NAME} "-create -output" $ {FRAMEWORK} / $ {FRAMEWORK_NAME} "|  echo

     # For Swift framework, Swiftmodule needs to be copied in the universal framework
     if [-d "$ {SIMULATOR_LIBRARY_PATH} / Modules / $ {FRAMEWORK_NAME} .swiftmodule /"];  then
     cp -f $ {SIMULATOR_LIBRARY_PATH} / Modules / $ {FRAMEWORK_NAME} .swiftmodule / * "$ {FRAMEWORK} / Modules / $ {FRAMEWORK_NAME} .swiftmodule /" |  echo
     fi

     if [-d "$ {DEVICE_LIBRARY_PATH} / Modules / $ {FRAMEWORK_NAME} .swiftmodule /"];  then
     cp -f $ {DEVICE_LIBRARY_PATH} / Modules / $ {FRAMEWORK_NAME} .swiftmodule / * "$ {FRAMEWORK} / Modules / $ {FRAMEWORK_NAME} .swiftmodule /" |  echo
     fi

     ########################
     # On Release, copy the result to release directory
     ########################
     OUTPUT_DIR = "$ {PROJECT_DIR} / build / $ {FRAMEWORK_NAME} - $ {CONFIGURATION} -iphoneuniversal /"

     rm -rf "$ OUTPUT_DIR"
     mkdir -p "$ OUTPUT_DIR"

     cp -r "$ {FRAMEWORK}" "$ OUTPUT_DIR"

     if [$ {REVEAL_ARCHIVE_IN_FINDER} = true];  then
     open "$ {OUTPUT_DIR} /"
     fi

Note

  • Bitcode packed only in archive for iphoneos sdk

  • otool -l -arch arm64 <yourframework_binary>|grep __LLVM to check if the bitcode is enabled, if you do not specify the arch parameter, there will be no __LLVM , since otool just prints one host architecture (simulator).

+7
source share

All Articles