Xcode 10:对我的App + Framework进行代码签名失败,因为对第三方依赖项框架(PromiseKit)签名失败。在Xcode 9中工作 [英] Xcode 10: Code Signing my App+Framework fails, because of failure signing 3rd party dependency framework (PromiseKit). Works in Xcode 9

查看:357
本文介绍了Xcode 10:对我的App + Framework进行代码签名失败,因为对第三方依赖项框架(PromiseKit)签名失败。在Xcode 9中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xcode 10-iOS12 swift项目,该项目链接到我自己的框架(还有Xcode 10 + iOS12)。

I have an Xcode 10 - iOS12 swift project that links against My own framework (also Xcode 10 + iOS12).

该应用程序项目将我的框架项目引用为子项目引用。

The app project is referencing my framework project as a sub-project reference.

我的框架项目引用PromiseKit .framework(一个通用框架-fat库),使用以下构建脚本制作:

My Framework project references PromiseKit.framework (a universal framework - fat library), made using the following build script:

# Merge Script

# 1
# Set bash script to exit immediately if any commands fail.
set -e

# 2
# Setup some constants for use later on.
FRAMEWORK_NAME="PromiseKit"

# 3
# If remnants from a previous build exist, delete them.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

# 4
# Build the framework for device and for simulator (using
# all needed architectures).
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch arm64 only_active_arch=no defines_module=yes -sdk "iphoneos"
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch x86_64 only_active_arch=no defines_module=yes -sdk "iphonesimulator"

# 5
# Remove .framework file if exists on Desktop from previous run.
if [ -d "${SRCROOT}/${FRAMEWORK_NAME}.framework" ]; then
rm -rf "${SRCROOT}/${FRAMEWORK_NAME}.framework"
fi

# 6
# Copy the device version of framework to Desktop.
cp -r "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${SRCROOT}/${FRAMEWORK_NAME}.framework"

# 7
# Replace the framework executable within the framework with
# a new version created by merging the device and simulator
# frameworks' executables with lipo.
lipo -create -output "${SRCROOT}/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"

# 8
# Copy the Swift module mappings for the simulator into the
# framework.  The device mappings already exist from step 6.
cp -r "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${SRCROOT}/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule"

# 9
# Delete the most recent build.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

当我使用Xcode 10(以及9.4.1)将Bitcode ON(包含My Framework参考和PromiseKit Fat库)归档到我的Parent App Project时,在Signing阶段出现以下错误:(无法验证位码​​)在PromiseKit.framework / PromiseKit中:错误无法从/ var / folders中提取包.... /(x86_64)-这表明它与模拟器分片有关)

When I go to archive my Parent App Project using Xcode 10 (And also 9.4.1) with Bitcode ON (that contains My Framework reference, and PromiseKit Fat library), I get the following error on the Signing stage: (Failed to verify bitcode in PromiseKit.framework/PromiseKit: error Cannot extract bundle from /var/folders..../(x86_64) - which suggests that it's simulator slice related)

如果我将管理器中的从位码重建选项设置为OFF,那么我将得到另一个错误:(代码签名 PromiseKit.framework失败)

If I turn the "Rebuild from Bitcode" option in the Organizer to OFF, then I get a different error: (Code signing "PromiseKit.framework" failed)

但是,如果我使用Xcode 9.4.1且Bitcode OFF,则出口并签收罚款。

However, if I use Xcode 9.4.1 With Bitcode OFF, then it exports and signs fine.

为什么要尝试重新签名子框架,我该怎么做才能缓解这些问题?我需要将存档与Xcode 10正常配合使用,并将将来的任何第三方依赖项添加到我的框架目标中。 (这是添加到我的Framework目标中的第一个动态框架依赖项。在我加入之前-为了便于开发而加入所有第3方,但是PromiseKit很难加入,因为对Objective-c的依赖性很大)。

Why is it trying to individually re-sign sub frameworks, and what can I do to alleviate the issues? I need the archiving to work normally with Xcode 10, along with any future third party dependencies being added to my framework target. (This is the first dynamic framework dependency added to my Framework target. Before I was "baking in" - in-boarding all 3rd parties for ease of development purposes, but PromiseKit is difficult to inboard due to extensive dependencies on Objective-c).

Xcode存档日志为:

The Xcode Archive log is:

 {
        code = 330;
        description = "Failed to resolve linkage dependency PromiseKit x86_64 -> @rpath/libswiftFoundation.dylib: Unknown arch x86_64";
        info =             {
        };
        level = WARN;
    },
            {
        code = 330;
        description = "Failed to resolve linkage dependency PromiseKit x86_64 -> @rpath/libswiftObjectiveC.dylib: Unknown arch x86_64";
        info =             {
        };
        level = WARN;
    },
            {
        code = 0;
        description = "Failed to verify bitcode in PromiseKit.framework/PromiseKit:\nerror: Cannot extract bundle from /var/folders/q5/hm9v_6x53lj0gj02yxqtkmd40000gn/T/IDEDistributionOptionThinning.RJD/Payload/MyAppName.app/Frameworks/PromiseKit.framework/PromiseKit (x86_64)\n\n";
        info =             {
        };
        level = ERROR;
        type = "malformed-payload";
    }
);

我尝试过的其他一些解决方案是使用PromiseKit的项目引用,而不是Framework引用,但是不起作用-因为我仍然需要来自主项目的框架引用,因为如果在没有FW引用的情况下运行,我会在运行时收到未加载库错误。使用项目参考进行归档时,也会发生相同的问题。

Some other solutions I tried was using a Project Reference to PromiseKit, instead of a Framework reference, however this doesn't work - in that I still need a framework reference from my main project, because I will get "library not loaded" error at runtime, if running without a FW reference. Same issue occurs when archiving while using a project reference.

推荐答案

尝试一下!它对我和其他许多人都有用:

Try this! It worked for me and many other people:

转到

构建阶段>添加>新建运行脚本阶段

Build phases > Add > New Run Script Phase

该代码适用于任何默认Shell,但我建议仅使用 / bin / sh

The code should work for any default shell, but I recommend just using /bin/sh

并包含以下代码:

# Type a script or drag a script file from your workspace to insert its path.
# skip if we run in debug
if [ "$CONFIGURATION" == "Debug" ]; then
echo "Skip frameworks cleaning in debug version"
exit 0
fi

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

EXTRACTED_ARCHS=()

for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done

echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"

echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

似乎有些框架提供了架构,不在应用程序中使用。
Xcode将拒绝对其进行签名。上面的脚本删除了未使用的体系结构。

It seems hat some frameworks ship architectures, that will not be used in the application. Xcode will refuse to sign them. The above script removes unused architectures.

信用:GitHub上的一个人,我找不到确切的来源了。

Credits: Some guy at GitHub, I can't find the exact source anymore.

这篇关于Xcode 10:对我的App + Framework进行代码签名失败,因为对第三方依赖项框架(PromiseKit)签名失败。在Xcode 9中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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