使用 Xcode 8 创建一个通用框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39890114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a universal framework using Xcode 8?
提问by ???? ?????
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.)
我公司的 iOS 框架旨在在真正的 iOS 设备上运行。所述框架目前作为 Xcode 项目中的附加目标生成,该项目也生成应用程序。(这使得调试框架相对容易。)
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 完成了此操作。有些材料解释了如何使用旧版本的 Xcode,但在一个版本的 Xcode 中有效的方法可能在以后无法使用或建议使用版本。(我们已经有了一种创建通用框架中断的方法。)我尝试使用一些 Xcode 8 之前的脚本,但它们都不起作用。
Has anyone managed to generate a universal framework for iOS using Xcode 8? If so, how can it be done?
有没有人设法使用 Xcode 8 为 iOS 生成通用框架?如果是这样,怎么做?
Thanks in advance for any help anyone can provide.
预先感谢任何人可以提供的任何帮助。
Aaron Adelman
亚伦·阿德尔曼
回答by iOSAddicted
It is possible since I am currently developing universal frameworks on iOS, watchOS and tvOS on Xcode 8.
这是可能的,因为我目前正在 Xcode 8 上的 iOS、watchOS 和 tvOS 上开发通用框架。
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
我这样做的方法是创建一个聚合目标(跨平台)并在其构建阶段添加一个运行脚本。该脚本基本上为 iphonesimulator 和 iphoneos 编译了 iOS 目标
After this it creates a new binary merging both of them(lipo -create -output)
在此之后,它会创建一个新的二进制文件合并它们(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.
考虑到脚本在这里可能不是您的问题,您的问题可能是设置您的有效架构、您的架构,甚至是您如何签署目标。我现在建议不要选中目标的常规设置中的自动管理签名选项,并手动设置您的配置文件和证书。
Run script:
运行脚本:
#!/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}"
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.
考虑到我在构建设置中将 Build Active Architecture Only 设置为 NO,有效的架构也设置为 arm64、x86_64、i386、armv7、armv7s。架构是 ${ARCHS_STANDARD} armv7s。
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.
我还设置了一个用户定义的构建设置 BITCODE_GENERATION_MODE 位码。使用此构建设置,我确保生成启用了位码的二进制文件。
回答by UnchartedWorks
build iOS/tvOS universal/fat framework
构建 iOS/tvOS 通用/胖框架
https://github.com/unchartedworks/universalbuild
https://github.com/unchartedworks/universalbuild
Usage:
用法:
universalbuild (-p|--project name.xcodeproj) (-s|--scheme schemename) (-c|--configuration configurationname)
Universalbuild (-p|--project name.xcodeproj) (-s|--scheme schemename) (-c|--configuration configurationname)
Example:
例子:
git clone https://github.com/cruisediary/Pastel.git
cd Pastel
universalbuild -p ./Pastel.xcodeproj -s Pastel -c Debug
回答by Himanshu Mahajan
Run script to create universal framework (no recursion issue)
运行脚本以创建通用框架(无递归问题)
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Next, work out if we're in SIM or DEVICE
if [ "false" == ${ALREADYINVOKED:-false} ]
then
export ALREADYINVOKED="true"
if [ ${PLATFORM_NAME} = "iphonesimulator" ]
then
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
else
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
fi
# 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}"
fi
回答by Eric Internicola
I too struggled with the same issue. I had a series of cocoapods that were used as source pods, but needed to be converted into binary pods. Between lots of googling, trial and error and hacking, I came up with a script that I have had great success with. It is based on the scripts you see here, but refactored into functions and some debugging output (that goes into the logs in /tmp) when something is missing.
我也遇到了同样的问题。我有一系列 cocoapods 用作源 pod,但需要转换为二进制 pod。在大量的谷歌搜索、反复试验和黑客攻击之间,我想出了一个我取得了巨大成功的脚本。它基于您在此处看到的脚本,但在缺少某些内容时重构为函数和一些调试输出(进入 /tmp 中的日志)。
That script can be found as a github gist here: https://gist.github.com/intere/bc380fa45ccf23976d3fc297522d29a8
该脚本可以在此处作为 github 要点找到:https: //gist.github.com/intere/bc380fa45ccf23976d3fc297522d29a8
FWIW, I've been using Xcode 9 (9.2, then 9.3, and now 9.4).
FWIW,我一直在使用 Xcode 9(9.2,然后是 9.3,现在是 9.4)。