ios - 运行失败 'lipo' ,lib有相同的架构

标签 ios xcodebuild lipo

我尝试构建静态框架。

所以我运行以下命令:

设备

xcodebuild
           -project MyAppLib.xcodeproj
           -sdk iphoneos
           -target $PRODUCT_FRAMEWORK
           -configuration Release clean build

模拟器

xcodebuild
           -project MyAppLib.xcodeproj
           -sdk iphonesimulator
           -target $PRODUCT_FRAMEWORK
           -configuration Release clean build

然而,当我尝试运行 lipo 时:

lipo -create build/Release-iphonesimulator/MyAppLib.framework/MyAppLib 
      build/Release-iphoneos/MyAppLib.framework/MyAppLib 
     -output MyAppLib.framework

我得到一个错误:

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/Release-iphonesimulator/MyAppLib.framework/MyAppLib and build/Release-iphoneos/MyAppLib.framework/MyAppLib have the same architectures (i386) and can't be in the same fat output file

我从 Xcode 成功构建了它,但从 CLI 两者具有相同的结构。

$ file MyAppLib.framework 给我:

MyAppLib.framework: Mach-O universal binary with 4 architectures: [i386: current ar archive] [arm_v7: current ar archive] [x86_64: current ar archive] [arm64]
MyAppLib.framework (for architecture i386): current ar archive
MyAppLib.framework (for architecture armv7):    current ar archive
MyAppLib.framework (for architecture x86_64):   current ar archive
MyAppLib.framework (for architecture arm64):    current ar archive

enter image description here


如果我尝试只在一个平台上运行,构建会成功,但我会得到一个奇怪的框架,我什至无法探索它:

enter image description here

编辑:

多平台脚本:

set -e

# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1

RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"

function build_static_library {
    # Will rebuild the static library as specified
    #     build_static_library sdk
    xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
    -target "${TARGET_NAME}" \
    -configuration "${CONFIGURATION}" \
    -sdk "${1}" \
    ONLY_ACTIVE_ARCH=NO \
    BUILD_DIR="${BUILD_DIR}" \
    OBJROOT="${OBJROOT}" \
    BUILD_ROOT="${BUILD_ROOT}" \
    SYMROOT="${SYMROOT}" $ACTION
}

function make_fat_library {
    # Will smash 2 static libs together
    #     make_fat_library in1 in2 out
    xcrun lipo -create "${1}" "${2}" -output "${3}"
}

# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi

# 2 - Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi

# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi

# 4 - Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi

# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"

# If we're currently building for iphonesimulator, then need to rebuild
#   to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi

# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"

# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"

# Copy the framework to the user's desktop
ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"

最佳答案

解决方案:

你没有问题。构建项目后出现的 MyAppLib.framework您的静态库,包含所有必需架构的切片。

构建项目后无需使用lipo

问题:

您的构建脚本“自动”构建您的目标两次,一次用于设备,一次用于模拟器。之后,它使用 lipo 将两个构建工件合并到一个胖库 (make_fat_library)。

然后将结果复制到:

#Ensure that the framework is present in both platform's build directories

因此,您在两个构建目录中都有一个 fat lib 框架。

现在您正在尝试合并这两个(已经合并的)胖库。由于两者都包含相同的切片,因此您会收到错误消息。

关于ios - 运行失败 'lipo' ,lib有相同的架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41000239/

相关文章:

ios - ARGB 图像的 CGContext.init 返回 nil

ios - 重写商店中已有的 IOS 应用程序

iOS 胖二进制文件和细化

xcode - 从命令行运行时,与在Jenkins中运行时相比,xcodebuild命令给出的结果不同

ios - 使用 lipo 将 iOS .dylib 合并到框架中会破坏位码重新编译

ios - OCMock ios7中“NICE”,“PARTIAL”和“MOCK”之间的区别

ios - 如何在 Qt Creator 中指定 iOS 模拟器?

xcodebuild - 使用 xcodebuild 将参数传递给 iOS 测试

ios - Xcode:只能归档一次聚合目标