我需要构建动态库作为框架。我有如下构建设置:
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构建吗?
答案 0 :(得分:2)
您需要选择iOS模拟器并为i386 arch构建框架。然后你可以使用lipo -create命令将两个框架合并为一个。
答案 1 :(得分:2)
有一种方法可以不退出Xcode。首先,您需要确定不支持i386架构的最新iOS版本(64位)。因此,如果仍然需要i386兼容框架,则必须通过选择旧的iOS版本来构建项目。我尝试使用iOS 10。
接下来要做的是,在 Build Settings 中提交的 有效架构 下添加所需的所有架构。 > 。
然后,使用您的 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 命令