如何构建 ios 框架以支持 i386 和 armv7

how to build ios framework to support i386 and armv7

我需要构建动态库作为框架。我的建筑设置如下:

ARCHS: armv7 armv7s arm64 i386 x86_64
ONLY_ACTIVE_ARCH: NO
VALID_ARCHS:  arm64 armv7 armv7s x86_64 i386

我为 ios 设备构建了目标,并使用 lipo -info 检查架构,结果是:

Architectures in the fat file: dyl are: armv7s armv7 arm64 

那么,xcode 是否不能同时为 i386 和 arm 构建?

您需要 select iOS 模拟器并为 i386 arch 构建一个框架。然后你可以使用 lipo -create 命令将两个框架合并为一个。

有一种方法可以不退出 Xcode。首先你需要确定最新的 iOS 版本(64 位)不支持 i386 架构。所以如果你仍然需要 i386 兼容的框架,你必须通过选择旧的 iOS 版本来构建你的项目。我试过 iOS 10.

接下来您要做的是,在 Valid Architectures 下添加您需要的所有架构 [=38] =]构建设置.

然后,使用 lipo 命令添加 运行 脚本以创建 FAT 文件。 (以下是我从互联网上获取的脚本,感谢那些编写该脚本的人)

#!/bin/sh

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"

# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"

# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"

最后您要做的是,通过选择 Generic iOS Device 选项构建框架。

然后验证,运行 lipo -info 命令