创建通用的iOS框架

3

我创建了一个通用的iOS框架。在Xcode中,它是一个“聚合目标”,使用构建脚本和lipo命令行工具将iphonesimulator和iphoneos二进制文件放入一个容器二进制文件中。构建iphonesimulator二进制文件的命令为:

xcodebuild -project MMFramework.xcodeproj -scheme "$SCHEME_NAME" \
    -sdk iphonesimulator -configuration ${CONFIGURATION} clean build \
    CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator

我已经用“MMFramework”替换了项目名称,但这不是问题所在。

在使用Xcode 6时,iphonesimulator二进制文件可以顺利构建。但是在使用Xcode 7时,我会遇到错误,例如:

// (with Xcode 7)
#import <sys/utsname.h>
^^Error: Could not build module 'Darwin'

此外,在Xcode7中,xcodebuild的行为有所不同。Xcode 6将我的xcodebuild命令转换为类似于以下调用的内容:
# with Xcode 6
CompileC build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/Objects-normal/i386/MPThreadIdAtom.o MPThreadIdAtom.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Volumes/Development/myProject/frameworks/MMFramework
    export LANG=en_US.US-ASCII
    /Applications/Xcode6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/michael/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/michael/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Xclang -fmodule-implementation-of -Xclang MMFramework -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode6.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.4.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=7.0 -iquote /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/MMFramework-generated-files.hmap -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/MMFramework-own-target-headers.hmap -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/MMFramework-all-non-framework-target-headers.hmap -ivfsoverlay /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/all-product-headers.yaml -iquote /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/MMFramework-project-headers.hmap -I/Volumes/Development/myProject/frameworks/MMFramework/build/Debug-iphonesimulator/include -I/Applications/Xcode6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/DerivedSources/i386 -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/DerivedSources -F/Volumes/Development/myProject/frameworks/MMFramework/build/Debug-iphonesimulator -MMD -MT dependencies -MF /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/Objects-normal/i386/MPThreadIdAtom.d --serialize-diagnostics /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/Objects-normal/i386/MPThreadIdAtom.dia -c /Volumes/Development/myProject/frameworks/MMFramework/MPThreadIdAtom.m -o /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphonesimulator/iOSMMFramework.build/Objects-normal/i386/MPThreadIdAtom.o

但是在Xcode 7中,你可以看到它终于相信iphonesimulator运行在ARM平台上。它似乎有些困惑,不知道它是否要构建一个iphonesimulator或iphoneos二进制文件。

# With Xcode 7
CompileC build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/Objects-normal/armv7/MPThreadIdAtom.o MPThreadIdAtom.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Volumes/Development/myProject/frameworks/MMFramework
    export LANG=en_US.US-ASCII
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/usr/local/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -gmodules -fmodules-cache-path=/Users/michael/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/michael/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Xclang -fmodule-implementation-of -Xclang MMFramework -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -miphoneos-version-min=7.0 -g -Wno-sign-conversion -fobjc-abi-version=2 -iquote /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/MMFramework-generated-files.hmap -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/MMFramework-own-target-headers.hmap -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/MMFramework-all-non-framework-target-headers.hmap -ivfsoverlay /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/all-product-headers.yaml -iquote /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/MMFramework-project-headers.hmap -I/Volumes/Development/myProject/frameworks/MMFramework/build/Debug-iphonesimulator/include -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/DerivedSources/armv7 -I/Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/DerivedSources -F/Volumes/Development/myProject/frameworks/MMFramework/build/Debug-iphonesimulator -MMD -MT dependencies -MF /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/Objects-normal/armv7/MPThreadIdAtom.d --serialize-diagnostics /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/Objects-normal/armv7/MPThreadIdAtom.dia -c /Volumes/Development/myProject/frameworks/MMFramework/MPThreadIdAtom.m -o /Volumes/Development/myProject/frameworks/MMFramework/build/Intermediates/MMFramework.build/Debug-iphoneos/iOSMMFramework.build/Objects-normal/armv7/MPThreadIdAtom.o
While building module 'Foundation' imported from /Volumes/Development/myProject/frameworks/MMFramework/MPThreadIdAtom.h:9:
While building module 'CoreFoundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
While building module 'Darwin' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:11:
In file included from <module-includes>:1:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/sys/cdefs.h:707:2: error: Unsupported architecture
#error Unsupported architecture

有人用Xcode7成功构建了通用的iOS框架吗?还是我犯了些错误?

Xcode 7是我的系统选择的版本:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

它被安装在/Applications/Xcode.app下,而Xcode 6则位于/Applications/Xcode6.app下。


这是我的构建脚本:

#!/bin/sh

echo "XXX 0"

######################
# Options
######################


FRAMEWORK_NAME="MMFramework"
SCHEME_NAME="iOSMMFramework"

SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"


######################
# Build Frameworks
######################

echo "XXX 1"

xcodebuild -project MMFramework.xcodeproj -scheme "$SCHEME_NAME" -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1

echo "XXX 2"

xcodebuild -project MMFramework.xcodeproj -scheme "$SCHEME_NAME" -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1

######################
# Create directory for universal
######################

echo "XXX 3"

rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"


######################
# Copy files Framework
######################

echo "XXX 5"

cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"


######################
# Make an universal binary
######################

echo "XXX 7"

lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo

echo "XXX 8"

# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
    cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi

if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
    cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi

echo "XXX 9"

我的Xcode通用目标包含两个构建阶段:“目标依赖项(0项)”和“运行脚本”。脚本如下:

iOSMMFramework/universal-buildscript.sh 2>&1 |tee ~/my-log.txt

my-log.txt仅用于调试,那里是我获取日志文件的地方。

Xcode 6的SDKROOT为"iphonesimulator8.4",Xcode 7的SDKROOT为"iphonesimulator9.2"。

我已将构建文件夹位置自定义为PROJECT_DIR/build。(将其更改回默认位置并没有任何区别。)


在Xcode 7.2(7C68)中不起作用。在Xcode 6.4(6E35b)中可以正常工作。

1个回答

0

我正在使用相同的命令,并能够创建通用框架。

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}"

你能试着从xcodebuild中移除clean build命令吗?我使用不同的shell脚本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接