简体   繁体   English

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

[英]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.

相关问题 适用于i386 / armv7的Sofia SIP构建 - Sofia SIP build for i386/armv7 Mac上的iOS模拟器是运行i386架构,而不是armv7? - iOS simulator on mac is running i386 architecture, not armv7? 在Mac 10.8上安装ffmpeg ios库armv7,armv7s,i386和Universal - Installing ffmpeg ios libraries armv7, armv7s, i386 and universal on Mac with 10.8 为armv7,armv7s,arm64,i386和通用构建ffmpeg iOS库 - Building ffmpeg iOS libraries for armv7, armv7s, arm64, i386 and universal 如何将libmms编译为适用于iPhone设备和模拟器的胖静态库(armv6,armv7和i386) - How to compile libmms to a fat static library for iPhone device and simulator(armv6,armv7 and i386) iOS 通用框架不构建 i386? - iOS Universal Framework not build i386? 体系结构i386 / armv7的未定义符号[cocoapods] - Undefined symbols for architecture i386/armv7 [cocoapods] 具有i386 x86_64 armv7 armv7s arm64的通用IOS静态库 - universal IOS static library with i386 x86_64 armv7 armv7s arm64 在带有10.9的xCode 6.1 Mac上安装ffmpeg ios库armv7,armv7s,i386和Universal - Installing ffmpeg ios libraries armv7, armv7s, i386 and universal on xCode 6.1 Mac with 10.9 如何合并为armv7和i386构建的两个.a文件? - How to merge two .a files which is built for armv7 and i386?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM