Ios 无法运行'lipo',Lib具有相同的体系结构

Ios 无法运行'lipo',Lib具有相同的体系结构,ios,xcodebuild,lipo,Ios,Xcodebuild,Lipo,我尝试构建静态框架 因此,我运行以下命令: 用于设备 用于模拟器 但是,当我尝试运行lipo时: 我得到一个错误: 致命错误: /Applications/Xcode.app/Contents/Developer/toolschains/xcodefault.xctoolschain/usr/bin/lipo: 构建/发布iphonesimulator/MyAppLib.framework/MyAppLib和 构建/发布iphoneos/MyAppLib.framework/MyAppLib具有

我尝试构建静态框架

因此,我运行以下命令:

用于设备

用于模拟器

但是,当我尝试运行lipo时:

我得到一个错误:

致命错误: /Applications/Xcode.app/Contents/Developer/toolschains/xcodefault.xctoolschain/usr/bin/lipo: 构建/发布iphonesimulator/MyAppLib.framework/MyAppLib和 构建/发布iphoneos/MyAppLib.framework/MyAppLib具有相同的功能 架构i386和不能在同一fat输出文件中

从Xcode I成功构建它,但从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
如果我尝试只为一个平台运行,构建成功,但我得到一个奇怪的框架,我甚至无法探索它:

编辑:

多平台脚本:

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

问题:

构建脚本自动构建目标两次,一次用于设备,一次用于模拟器。之后,它将两个构建人工制品合并到一个fat库中,并使用lipo生成fat库

然后将结果复制到:

确保框架存在于平台的两个构建目录中

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


现在您正试图合并这两个已经合并的fat库。由于两者都包含相同的切片,因此会出现错误

我想知道Xcode会将所有的体系结构都显示出来。我怀疑您正在运行构建阶段脚本。如果不是:将i386、x86_64添加到您的有效体系结构中,并将Build Active Architecture Only设置为NO以供发布。另外:文件输出来自什么。Xcode版本还是CLI版本?另外,奇怪的框架有什么问题吗?@shallowthough我只构建了用于调试和发布的活动架构。我还发布了多平台脚本。我是否需要为iOS和模拟器运行构建静态框架?在strange framework下,我的意思是MyAppLib.framework是一个文件而不是文件夹。如果您想在应用程序中使用此库,您希望能够在设备上使用它,并在模拟器中调试您的应用程序。所以,是的,您确实想要为设备和模拟器构建。您的构建脚本已经创建了fat库。不用再做了。输出为MyAppLib.framework。这看起来很好。您仍然应该将i386、x86_64添加到您的有效体系结构中这是您的静态库,包装在framewor中。MyAppLib.framework应该是一个目录,而不是一个文件。在终端中:ls-la包含文件夹。它看起来像是以d开头的目录:drwxr-xr-x6 yorName staff 204 Dec 5 14:09 MyAppLib.framework?@shallowthough否,MyApp.framework是一个文件:-rw-r-r-。我发布的脚本在我的桌面上生成MyApp.framework,但是lipo-create。。。命令生成文件而不是包。我将尝试在我的desctop上创建的框架文件上运行lipo。我的项目中也面临类似的架构相关问题。请浏览下面的链接并帮助我解决这个问题。
lipo -create build/Release-iphonesimulator/MyAppLib.framework/MyAppLib 
      build/Release-iphoneos/MyAppLib.framework/MyAppLib 
     -output 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
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"