使用Xcode 8创建通用框架? [英] Creating a universal framework using Xcode 8?

查看:96
本文介绍了使用Xcode 8创建通用框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司的iOS框架适用于真正的iOS设备。所述框架当前作为Xcode项目中的附加目标生成,该Xcode项目还生成应用程序。 (这使得调试框架相对容易。)

My company's iOS framework is meant to work on a real iOS device. Said framework is currently generated as an additional target within a Xcode project which also generates an application. (This makes it relatively easy to debug the framework.)

我们最近也收到了让它在模拟器中工作的请求。我现在可以这样做,下一步是创建一个既可以在真实设备上也可以在模拟器中运行的编译版本。遗憾的是,我无法找到任何材料,表明任何人都使用Xcode 8来完成此操作。有些材料解释了如何使用旧版本的Xcode,但在一个版本的Xcode中工作的可能不起作用或在以后建议版。 (我们已经有了一种在我们身上创建通用框架的方法。)我尝试使用一些pre-Xcode 8脚本,但没有一个工作。

We recently got requests to also make it work in the simulator, too. I can now make it do so, and the next step is to create a compiled version which works both on a real device and in the simulator. Sadly, I have not been able to locate any material indicating that anyone has done this using Xcode 8. There are materials explaining how do using older versions of Xcode, but what works in one version of Xcode may not work or be advisable in a later version. (We already had one method of creating a universal framework break on us.) I tried using a few pre-Xcode 8 scripts, but none of them worked.

有没有人设法使用Xcode 8为iOS生成通用框架?如果是这样,怎么办呢?

Has anyone managed to generate a universal framework for iOS using Xcode 8? If so, how can it be done?

提前感谢任何人都可以提供帮助。

Thanks in advance for any help anyone can provide.

Aaron Adelman

Aaron Adelman

推荐答案

因为我目前正在Xcode 8上开发iOS,watchOS和tvOS上的通用框架。

It is possible since I am currently developing universal frameworks on iOS, watchOS and tvOS on Xcode 8.

我这样做的方法是创建一个Aggregate目标(跨平台)并在其构建阶段添加一个运行脚本。该脚本基本上编译了iphonesimulator和iphoneos的iOS目标

The way I do it is creating an Aggregate target(cross platform) and add a run script in its build phase. The script basically compiles the iOS target for iphonesimulator and iphoneos

之后它创建了一个合并两者的新二进制文件(lipo -create -output)

After this it creates a new binary merging both of them(lipo -create -output)

您是否介意发布当前的构建脚本以生成通用框架,以便我可以指导您做错了什么?

Would you mind posting your current build script for generating a universal framework so I can guide you with what you are doing wrong?

考虑到脚本可能不是您的问题,您的问题可能是设置有效的体系结构,您的体系结构甚至是如何签署目标。我现在建议,不要选中目标常规设置中的自动管理签名选项,并手动设置配置文件和证书。

Take in consideration that the script could not be your issue here, your issue could be setting up your valid architectures, your architectures or even how you are signing the target. I recommend for now, to leave the Automatically manage signing option in your General settings of your target unchecked, and set your provisioning profiles and certs manually.

运行脚本:

    #!/bin/sh

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

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

# Step 1. Build Device and Simulator versions on iOS
xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}"  -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' clean build
xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}" -sdk iphoneos 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}/iOS"

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

# Step 4. Convenience step to copy the framework to the project's directory
mkdir -p "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"

cp -R "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework" "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"


# Step 6. Create .tar.gz file for posting on the binary repository
cd "${TMPDIR}"

# We nest the framework inside a Frameworks folder so that it unarchives correctly
tar -zcf "${PROJECT_NAME}.framework.tar.gz" "${PROJECT_NAME}/Frameworks/"
mv "${PROJECT_NAME}.framework.tar.gz" "${PROJECT_DIR}/"

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

考虑到我在构建设置中将Build Active Architecture Only设置为NO,同样有效的架构设置为arm64,x86_64,i386,armv7,armv7s。架构是$ {ARCHS_STANDARD} armv7s。

Take in consideration that I set the Build Active Architecture Only to NO in the build settings, also the valid Architectures are set as arm64, x86_64, i386, armv7, armv7s. The Architectures are ${ARCHS_STANDARD} armv7s.

我还设置了用户定义的构建设置BITCODE_GENERATION_MODE bitcode。使用此构建设置,我确保生成启用了bitcode的二进制文件。

I also set a user defined build setting BITCODE_GENERATION_MODE bitcode. With this build setting I make sure to generate binaries with bitcode enabled.

这篇关于使用Xcode 8创建通用框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆