制作多架构iOS和Mac OS框架

克里斯·马歇尔

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

基本上,我需要与旧方法相同的结果(在本教程中很好解释了)。

我尝试了这个,但是问题是该框架仅生成了几个ARM二进制文件。我也需要在其中安装i386 / x86_64二进制文件,因此它将是一个完整的框架。

我确定我正在忽略某些东西。有人对这个无知的人有头绪吗?

克里斯·马歇尔

是的,对于大多数人来说,这似乎不是很有趣。

呃,好吧。我确实使用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"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Mac OS X Yosemite上安装Ionic框架的问题

Mac OS:g ++无法添加框架支持

如何在Cython中链接Mac OS框架

Mac OS X上Python的框架版本与非框架版本之间的差异

使用实体框架和 MySql 在 Mac OS 上运行 Razor Pages Web App

如何使用OOP在Tkinter中制作多个框架?

如何在iOS和OS X之间创建一个共享框架

Mono 框架构建错误 - Mac OSX

Mac OS X中AUI框架中工具栏中的组合框

在Mac OS X中获取AWT框架的可绘制区域吗?

Mac OS X 10.13 CoreBluetooth框架上的CBPeripheralStateDisconnecting状态之后,外围状态永远不会改变

是否有任何 python 函数可以调用像 ctypes wilndll 这样的 Mac OS 框架?

在最近的OS和框架更新之后,在iOS上启动/调试NativeScript应用程序时出现问题

Mac OS Pycharm上的Python通过“将matplotlib.pyplot导入为plt”给出框架错误

是否可以为iOS,模拟器和*和Mac创建胖框架?

适用于Mac OS和iOS的通用类

制作多语言iOS应用

适用于iOS框架的Arm64e架构

如何使用实体框架工作核心中的资源来制作多语言应用程序?

TortoiseSVN和Mac OS

JavaScript框架和框架集

不同DbContext和不同架构之间的实体框架关系

一起使用 WPF 和实体框架 - 什么架构?

Tesseract / Tess4J在Mac OS X上崩溃:问题框架:C [libtesseract.dylib + 0xcf72] tesseract :: TessResultRenderer ::〜TessResultRenderer()+ 0x10

实体框架架构验证失败

iOS静态和动态框架说明

Flutter Android库和iOS框架

Unix,Mac OS和Linux?

将框架嵌入框架(iOS 8+)