编译启用位码的iOS库

我需要发布一个框架启用bitcode,这是一个麻烦。 我将项目设置中的“启用位码”设置为“是”,并为实际设备和模拟器build立干净的。

我想testing库,所以我把它集成到我为此创build的一个新的应用程序,但现在它只为模拟器build立。 当我试图build立一个真正的设备,我得到:

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) 

就像我说的,我已经build立了Bitcode启用,所以我不知道为什么会发生这种情况。

有任何想法吗? 谢谢

AFAIK,当您使用Xcode构build应用程序时,只有在进行归档时才会包含Bitcode,原因 – 只需debugging或testing应用程序/库时减less编译时间。

为了确保Xcode在每次构build时都能发射位码,可以将-fembed-bitcode标志添加到Other C flagsOther linker flags

在这里输入图像说明

在这里输入图像说明

此外,检查二进制文件是否包含位码的最简单方法是使用otoolgrep

otool -l binary_name | grep __LLVM

如果没有bitcode或空输出,您将看到一个或多个segname __LLVM条目。

RunScript代码的另一种方法:(构build设置 – 构build阶段RunScript) 在这里输入图像说明

 # define output folder environment variable UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # 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 mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # 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}/"