【问题标题】:Making Multi-Architecture iOS and Mac OS Frameworks制作多架构 iOS 和 Mac OS 框架
【发布时间】:2015-01-07 20:41:42
【问题描述】:

我在使用新的 Xcode 6 动态框架目标开发框架时遇到问题。

基本上,我需要与旧方法相同的结果 (Explained very well in this tutorial)。

我尝试了this,但问题是该框架只生成了几个 ARM 二进制文件。我还需要在其中包含 i386/x86_64 二进制文件,因此它将是一个完整的框架。

我确定我忽略了一些东西。有人知道这个无知的人吗?

【问题讨论】:

  • 嗯...我对此进行的研究越多,我就越意识到新目标并不是我真正需要的。看起来我仍然会运行命令行构建并使用 lipo 编写。
  • 我将不得不四处看看是否也可以使用 dyLibs 完成类似的操作。不是优先事项。我的回答中的方法效果很好,尽管投反对票很小。这是一个准确且非常相关的答案。

标签: xcode frameworks ios8


【解决方案1】:

是的,看起来这对大多数人来说不是很有趣。

啊,好吧。我确实使用了更好的 Wenderlich 脚本版本,我将在此处发布。

这具有成为“一等公民”框架的显着优势;不是新目标生成的仅限 iOS8 的动态版本。

#! /bin/sh

# This was cribbed from here: http://www.raywenderlich.com/65964/create-a-framework-for-ios

# This script will build a multiplatform framework for the project referenced from the $FRAMEWORK_PRODUCT_NAME environment variable.
# This variable needs to be set as a user-defined value in the build settings of this target (an aggregate target that just runs this script).
# The project must have a static lib target, with the exact name defined by $FRAMEWORK_PRODUCT_NAME, and the output from that target needs to be
# a static lib that is "lib${FRAMEWORK_PRODUCT_NAME}.a". The static lib target needs to have a "Debug" and a "Release" configuration, with the
# debug configuration embedding symbols/profiling information (as opposed to a separate DSYM file).
# No stripping should be done for non-debug in either configuration (but it is advised to strip debug symbols in "Release").
# The aggregate target should also define the $DELIVERABLE_DIRECTORY environment variable. This is a relative POSIX path from the ${BUILD_DIR}
# location, to a place that the user wants to deliver the framework. The script will create a "Framework" directory there, with a "Debug" and
# a "Release" directory; each containing a copy of the framework.
# The static lib target needs to create a "Headers" directory with exported headers, and a "Resources" directory (even if it is empty).

set -e

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

# This function actually runs the static lib target build, in the configuration requested.
# INPUT: SDK, configuration (either "Debug" or "Release"), target name

function build_static_library
{
    xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
    -sdk "${1}" \
    -configuration "${2}" \
    -target "${3}" \
    ONLY_ACTIVE_ARCH=NO \
    BUILD_DIR="${BUILD_DIR}" \
    OBJROOT="${OBJROOT}" \
    BUILD_ROOT="${BUILD_ROOT}" \
    SYMROOT="${SYMROOT}" $ACTION
}

# This function will build the iphoneos and iphonesimulator versions of the framework, and will
# use lipo to merge them together into a "fat" binary that contains x86 and ARM code.
# It will also copy the headers and the resources for the framework, so the static lib target needs to create
# a "Headers" directory with exported headers, and a "Resources" directory (even if it is empty).
# INPUT: configuration (example: "Release" or "Debug").

function buildTwoArchitectures
{
    # 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
    if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
        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
        SDK_VERSION=${BASH_REMATCH[1]}
    else
        echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
        exit 1
    fi

    if [ "$SDK_PLATFORM" == "iphoneos" ]; then
        OTHER_PLATFORM="iphonesimulator"
    else
        OTHER_PLATFORM="iphoneos"
    fi

    # Build the other platform.
    build_static_library "${SDK_PLATFORM}${SDK_VERSION}" "${1}" "${FRAMEWORK_PRODUCT_NAME}"
    build_static_library "${OTHER_PLATFORM}${SDK_VERSION}" "${1}" "${FRAMEWORK_PRODUCT_NAME}"

    BUILT_PRODUCTS_DIR="${BUILD_DIR}/${1}-${SDK_PLATFORM}"
    OTHER_BUILT_PRODUCTS_DIR="${BUILD_DIR}/${1}-${OTHER_PLATFORM}"

    # Create the path to the real Headers dir
    mkdir -p "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Versions/A/Headers"
    mkdir -p "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Versions/A/Resources"

    # Create the required symlinks
    ln -sfh A "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Versions/Current"
    ln -sfh Versions/Current/Headers "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Headers"
    ln -sfh Versions/Current/Resources "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Resources"
    ln -sfh "Versions/Current/${FRAMEWORK_PRODUCT_NAME}" "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/${FRAMEWORK_PRODUCT_NAME}"

    # Copy the public headers into the framework
    cp -a "${BUILT_PRODUCTS_DIR}/Headers/" "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Versions/A/Headers"

    # Copy the resources into the framework.
    cp -a "${BUILT_PRODUCTS_DIR}/Resources/" "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Versions/A/Resources"

    # Join the 2 static libs into 1 and push into the .framework
    lipo    -create "${BUILT_PRODUCTS_DIR}/libNKPTPF.a" "${OTHER_BUILT_PRODUCTS_DIR}/libNKPTPF.a" \
            -output "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework/Versions/A/${FRAMEWORK_PRODUCT_NAME}"

    # Move the resultant framework to our delivery location.
    rm -drf "${BUILD_DIR}/${DELIVERABLE_DIRECTORY}/Framework/${1}/"
    mkdir -p "${BUILD_DIR}/${DELIVERABLE_DIRECTORY}/Framework/${1}/"
    mv -f "${BUILD_DIR}/${FRAMEWORK_PRODUCT_NAME}.framework" "${BUILD_DIR}/${DELIVERABLE_DIRECTORY}/Framework/${1}/"
}

# Make it so, numbah one...
buildTwoArchitectures "Debug"
buildTwoArchitectures "Release"

【讨论】:

  • 虽然这构成了一个静态框架——而帖子标题谈论的是动态
  • 嗯...我是海报。我回答了我自己的问题。在点击“downvote”按钮之前,您是否真的阅读了我写的内容?圣牛。
  • a) 我看到你是张贴者,b) 我什至说了问题所在。 :该主题谈到了一个动态框架,我只是说这个答案不适合这个问题。 [我实际上在寻找一种使用动态库来做到这一点的方法] c)不要把它当回事;)——哦,我希望我更年轻——并且尽量不要居高临下,因为它肯定不会随时随地为您提供帮助
  • 我删除了我的讽刺评论。为胡思乱想道歉。我就这样吧。
  • 哦,顺便说一句。这也将构建将在 Mac OS X 上运行的框架,只要您不引用任何特定于 iOS 的内容。我使用它为 iOS 和 Mac OS X 提供完整的 WiFi/BSD 套接字/PTP-IP 堆栈。
猜你喜欢
  • 1970-01-01
  • 2010-11-29
  • 2014-08-13
  • 1970-01-01
  • 1970-01-01
  • 2018-11-23
  • 1970-01-01
  • 1970-01-01
  • 2011-09-28
相关资源
最近更新 更多