是否可以使用bitcode创建通用iOS框架?

编程入门 行业动态 更新时间:2024-10-24 12:26:33
本文介绍了是否可以使用bitcode创建通用iOS框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

根据我的理解, bitcode 允许使用中间二进制格式生成二进制文件。所以这是编译到ARM或x64架构之前的步骤。

From what I understood, bitcode allows to generate binaries with an intermediary binary format. So it is the step before compiling to an ARM or x64 architecture.

可以创建真实 .framework iOS 8以来的iOS文件。但是,默认情况下,框架文件仅针对一种体系结构进行编译(模拟器,iPhone)。当想要分发 .framework 文件时,最好提供与iOS模拟器兼容的文件,并且还可以部署到iPhone。可以使用 lipo 找到不同的脚本示例来创建这样的胖文件。

It is possible to create "real" .framework file for iOS since iOS 8. However, framework files are compiled for only one architecture by default (emulator, iPhone). When one wants to distribute a .framework file, it is better to provide a file compatible with the iOS emulator and also deployable to an iPhone. Different examples of scripts can be found to create such a fat file using lipo.

但是,是否可以只分发编译为bitcode的 .framework 而不必创建具有不同体系结构的胖文件?

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

不幸的是,即使为我的 .framework 启用了bitcode:

Unfortunately, even with bitcode enabled for my .framework:

  • 默认情况下会创建不同的文件根据目标架构
  • 即使为框架目标启用了存档菜单,我也无法找到结果,即使在我的管理器视图中也是如此。

我是否误解了 bitcode 的概念,或者我错过了什么?

Do I misunderstand something in the concept of bitcode, or do I miss something?

推荐答案

您需要提供通用的平面框架。这是由 lipo 创建的。

You need to provide a universal flat framework. Which is created by lipo.

  • 启用Bitcode,目标 - >构建设置 - >启用Bitcode 到是
  • 添加构建目标创建通用框架

  • Enable Bitcode, Targets->Build Setting->Enable Bitcode to Yes
  • Add build target to create universal framework

创建聚合目标并将以下脚本复制到构建短语 - >运行脚本:

Create a Aggregate target and copy following script to 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}-iphonesimulator # 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

注意

  • bitcode仅打包在iphoneos sdk的 archive build

otool -l -arch arm64< yourframework_binary> | grep __LLVM 检查是否包含bitcode ,如果你没有指定 arch 参数,那么将没有 __ LLVM ,因为 otool 只打印一个主机拱门(模拟器)。

otool -l -arch arm64 <yourframework_binary>|grep __LLVM to check whether bitcode is included, if you don't specify the arch parameter, there will be no __LLVM, since otool just print one host arch(simulator).

更多推荐

是否可以使用bitcode创建通用iOS框架?

本文发布于:2023-11-16 22:01:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   框架   bitcode   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!