[英]how to build ios framework to support i386 and armv7
I need to build dynamic library as framework. 我需要建立动态库作为框架。 I have building settings as follows: 我的建筑设置如下:
ARCHS: armv7 armv7s arm64 i386 x86_64
ONLY_ACTIVE_ARCH: NO
VALID_ARCHS: arm64 armv7 armv7s x86_64 i386
I built target for ios device, and used lipo -info to check the architectures, the result is : 我为ios设备构建了目标,并使用lipo -info检查了体系结构,结果是:
Architectures in the fat file: dyl are: armv7s armv7 arm64
So, does xcode can not build for both i386 and arm? 那么,xcode不能同时为i386和arm生成吗?
You need to select iOS simulator and build a framework for i386 arch. 您需要选择iOS模拟器并为i386 arch构建一个框架。 Then you can use lipo -create command to merge the two framework into one. 然后,您可以使用lipo -create命令将两个框架合并为一个。
There is a way of doing it without exiting the Xcode. 有一种方法可以不退出Xcode。 First you need to identify the latest iOS versions (64 bits) do not support i386 architecture. 首先,您需要确定不支持i386架构的最新iOS版本(64位)。 So if you still need i386 compatible framework, you have to build your project by selecting an old iOS version. 因此,如果仍然需要i386兼容框架,则必须通过选择旧的iOS版本来构建项目。 I tried with iOS 10. 我尝试使用iOS 10。
Next thing that you have to do is, add all the architectures that you need under Valid Architectures filed in the Build Settings . 下一步,您需要在Build Settings中提交的Valid Architectures下添加所需的所有架构。
Then, add a Run Script with your lipo commands to create the FAT file. 然后,使用lipo命令添加运行脚本以创建FAT文件。 (Following script I've taken from the Internet sometime back & credit goes to those who wrote that) (以下是我有时从互联网上获取的脚本,写给那些脚本的人应该归功于它)
#!/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}"
Finally what you have to do is, build the framework by selecting Generic iOS Device option. 最后,您要做的是通过选择“ 通用iOS设备”选项来构建框架。
Then to verify, run the lipo -info command 然后进行验证,运行lipo -info命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.