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

问题描述 投票:2回答:2

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

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构建吗?

ios iphone ios-simulator
2个回答
2
投票

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


2
投票

有一种方法可以在不退出Xcode的情况下完成。首先,您需要确定最新的iOS版本(64位)不支持i386架构。因此,如果您仍需要i386兼容框架,则必须通过选择旧的iOS版本来构建项目。我试过iOS 10。

enter image description here

接下来您需要做的是,在Build Settings中提交的Valid Architectures下添加您需要的所有体系结构。

enter image description here

然后,使用lipo命令添加Run Script以创建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选项来构建框架。

enter image description here

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.