gpt4 book ai didi

ios - 创建通用的 iOS 框架

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:21 24 4
gpt4 key购买 nike

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

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'

此外,xcodebuild 在 Xcode7 中的行为有所不同。 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-binary 感到困惑。

# 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

那么,有没有人用Xcode 7成功搭建过一个通用的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) 它可以工作。

最佳答案

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

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 命令吗?我使用不同的 shellscript。

关于ios - 创建通用的 iOS 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34263847/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com