Xcode 10 的胖框架脚本? [英] Fat Framework Script for Xcode 10?

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

问题描述

我在我的方案中存档的后期操作中使用了这个脚本来制作一个 FAT 二进制框架.一种适用于模拟器和实际设备的设备.

I used this script in the post-action of the archive in my scheme to make a FAT binary framework. One that will work on the simulator and actual device.

https://gist.github.com/gauravkeshre/eabb2a13ef6d673fadec84ca60b56b05

有人知道如何将其转换为与 Xcode 10 一起使用吗?

Does anyone know how to convert it to work with Xcode 10?

使用遗留构建系统修复错误,但我宁愿不依赖它.

Using the legacy build system fixes the errors, but I would rather not rely on it.

这是脚本本身:

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1

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

if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"

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

echo "Building for iPhoneSimulator"
xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone XS' ONLY_ACTIVE_ARCH=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

# Step 1. Copy the framework structure (from iphoneos build) to the universal folder
echo "Copying to output folder"
cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

# Step 2. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule"
fi

# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "Combining executables"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"

# Step 4. Create universal binaries for embedded frameworks
for SUB_FRAMEWORK in $( ls "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks" ); do
BINARY_NAME="${SUB_FRAMEWORK%.*}"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${SUB_FRAMEWORK}/${BINARY_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
done

# Step 5. Convenience step to copy the framework to the project's directory
echo "Copying to project dir"
yes | cp -Rf "${UNIVERSAL_OUTPUTFOLDER}/${FULL_PRODUCT_NAME}" "${PROJECT_DIR}"

open "${PROJECT_DIR}"

fi

** BUILD SUCCEEDED ** 后输出日志中的错误:

The errors in the output log after ** BUILD SUCCEEDED **:

Copying to output folder
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-iphonesimulator/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/.: unable to copy extended attributes to /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/i386.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/x86_64.swiftdoc: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/x86_64.swiftmodule: No such file or directory
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Modules/ContactAtOnceMessaging.swiftmodule/i386.swiftdoc: No such file or directory

然后:

fatal error: /Applications/Xcode 10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't create temporary output file: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/ContactAtOnceMessaging.lipo (No such file or directory)
ls: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework/Frameworks: No such file or directory
Copying to project dir
cp: /Users/aaronbratcher/Library/Developer/Xcode/DerivedData/iOS-Messaging-SDK-dnynwhbesxdjhmedgaxbdcjgaksx/Build/Intermediates.noindex/ArchiveIntermediates/ContactAtOnceMessaging/BuildProductsPath/Release-universal/ContactAtOnceMessaging.framework: No such file or directory

一旦进入 Release-universal 文件夹,第一条路径就会停止,因为没有 .framework 文件夹.相反,框架的内容在那里.

The first path falters once you get inside the Release-universal folder because there is no .framework folder. Instead, the contents of the framework are there.

推荐答案

你不需要改变任何东西.只需在框架目标的构建设置中将 skip_install 设置为 NO 即可.在归档之前,还要从 ${PROJECT_DIR} 中删除 .framework.

You don't need to change anything. Just set skip_install to NO in the build setting of the framework target. Also remove the .framework from ${PROJECT_DIR} before archiving.

如果仍然无法解决问题,请使用 ${PROJECT_NAME}_archive.log 中所说的错误来编辑您的问题.

If it still doesn't work, edit your question with what the ${PROJECT_NAME}_archive.log says went wrong.

也尝试在 xcode 10 中使用旧系统进行构建.文件 -> 工作区设置 -> 构建系统

Also try building with legacy system in xcode 10. File -> Workspace Settings -> Build System

编辑 2:出于某种原因,Xcode 10 后操作 bash 脚本的行为与以前的 Xcode 版本不同.尤其是这行:

Edit 2: For some reason Xcode 10 post action bash scripts behave differently for previous Xcode versions. Especially the line:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${FULL_PRODUCT_NAME}" "${UNIVERSAL_OUTPUTFOLDER}/"

在 Xcode 10 中,这会将 .framework 的内容复制到 ${UNIVERSAL_OUTPUTFOLDER},而在 Xcode 9.3 中,它将整个 .framework 复制到文件夹中.

In Xcode 10 this will copy the contents of the .framework to the ${UNIVERSAL_OUTPUTFOLDER}, whereas in Xcode 9.3 it will copy the whole .framework to the folder.

所以如果你把这行改成:

So if you change this line to:

cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/" "${UNIVERSAL_OUTPUTFOLDER}"

该脚本可以在 Xcode 10 中正常运行.

The script will work fine in Xcode 10.

我使用的脚本:

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1

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

if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"

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

echo "Building for iPhoneSimulator"
xcodebuild -workspace "${WORKSPACE_PATH}" -scheme "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone XS' ONLY_ACTIVE_ARCH=NO ARCHS='i386 x86_64' BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" BITCODE_GENERATION_MODE=bitcode clean build

# Step 1. Copy the framework structure (from iphoneos build) to the universal folder
echo "Copying to output folder"
cp -R "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/" "${UNIVERSAL_OUTPUTFOLDER}"

# Step 2. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Modules/${TARGET_NAME}.swiftmodule"
fi

# Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "Combining executables"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${EXECUTABLE_PATH}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${EXECUTABLE_PATH}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${EXECUTABLE_PATH}"

echo "Combining executables end"

# Step 4. Create universal binaries for embedded frameworks
for SUB_FRAMEWORK in $( ls "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks" ); do
BINARY_NAME="${SUB_FRAMEWORK%.*}"
echo "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${SUB_FRAMEWORK}/${BINARY_NAME}" "${ARCHIVE_PRODUCTS_PATH}${INSTALL_PATH}/${TARGET_NAME}.framework/Frameworks/${SUB_FRAMEWORK}/${BINARY_NAME}"
done

# Step 5. Convenience step to copy the framework to the project's directory
echo "Copying to project dir"
yes | cp -Rf "${UNIVERSAL_OUTPUTFOLDER}/${FULL_PRODUCT_NAME}" "${PROJECT_DIR}"

open "${PROJECT_DIR}"

fi

这篇关于Xcode 10 的胖框架脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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