7

情况

我刚刚迁移到最新的 XCode12.4,因此我已将所有依赖项预编译为xcframeworks. 现在我xcconfig用来链接其中一些框架。我有一个应用程序,它使用了几个预编译xcframeworks的 .

这是一个共享文件Dependencies/Frameworks.xcconfig,可以轻松访问所有依赖项,并且与预编译的依赖项位于同一存储库中。

/// Path into xcode specific builds
FRAMEWORKS_PATH_12_4 = Frameworks/XCode12.4
FRAMEWORKS_PATH_11_5 = Frameworks/XCode11.5 // old path, obsolete
FRAMEWORKS_PATH_10_3 = Frameworks/XCode10.3 // old path, obsolete

/// All firebase related frameworks
FIREBASE_FRAMEMWORKS = -framework FirebaseAnalytics -framework FirebaseCore -framework FirebaseCoreDiagnostics -framework FirebaseCrashlytics -framework FirebaseInstallations -framework GoogleAppMeasurement -framework GoogleDataTransport -framework GoogleUtilities -framework PromisesObjC -framework nanopb 

/// Summary of all Frameworks provided by this repo
ALL_FRAMEWORKS = -framework ZipArchive -framework Alamofire -framework RxSwift -framework RxCocoa -framework RxRelay -framework Snapkit -framework SVGKit -framework Lottie -framework AudioKit -framework NSLoggerSwift $(FIREBASE_FRAMEMWORKS)

现在我的应用程序中的框架链接到 2 个框架,它看起来像这样

/// Include the dependency repo definitions
#include "../Dependencies/Frameworks.xcconfig"

/// Define this for the carthage build step
DEPENDENCIES_PATH[config=RC]         = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)
DEPENDENCIES_PATH[config=Release]    = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)
DEPENDENCIES_PATH[config=T1]         = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)
DEPENDENCIES_PATH[config=Debug]      = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)

/// Setup search paths
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEPENDENCIES_PATH)/**

/// Include required frameworks
OTHER_LDFLAGS = $(inherited) -framework Alamofire -framework ZipArchive

问题

现在,当我针对通用设备构建或存档时,一切都很好。但是当我为模拟器构建时,我得到了这个错误

Could not find module 'Alamofire' for target 'x86_64-apple-ios-simulator'; found: arm64, armv7-apple-ios, arm64-apple-ios, arm, armv7

我认为这是由于这里的递归搜索路径

/// Setup search paths
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEPENDENCIES_PATH)/**

当我删除递归搜索路径时,出现此错误

No such module 'Alamofire'

解决方法

似乎可行的方法是告诉编译器xcframework像这样深入查看内部

/// Setup search paths
FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*] = $(inherited) $(DEPENDENCIES_PATH)/Alamofire.xcframework/ios-arm64_armv7 $(inherited) $(DEPENDENCIES_PATH)/ZipArchive.xcframework/ios-arm64_armv7
FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*] = $(inherited) $(DEPENDENCIES_PATH)/Alamofire.xcframework/ios-arm64_i386_x86_64-simulator $(DEPENDENCIES_PATH)/ZipArchive.xcframework/ios-arm64_i386_x86_64-simulator

但老实说,我在项目中有几十个依赖项,维护它非常乏味。

问题

我如何告诉我的框架xcconfig文件它应该正确的架构文件夹xcframework中查找实际的framework

4

1 回答 1

2

在 Xcode 中,将 Run Script 预构建操作添加到您的方案中。

将此脚本放入 Run Script 预构建操作中:

OLD_DIR="${PWD}"
rm -rf "${CONFIGURATION_TEMP_DIR}/XCFrameworkSlices"
mkdir -p "${CONFIGURATION_TEMP_DIR}/XCFrameworkSlices"
cd "${CONFIGURATION_TEMP_DIR}/XCFrameworkSlices"
SUFFIX="arm[v6][74]"
if [[ ! -z "$LLVM_TARGET_TRIPLE_SUFFIX" ]]; then
   SUFFIX=$LLVM_TARGET_TRIPLE_SUFFIX
fi
find $DEPENDENCIES_PATH/*.xcframework/$SWIFT_PLATFORM_TARGET_PREFIX-*$SUFFIX -type d -depth 0 -print0 | xargs -0 -I {} sh -c 'ln -s "$1" "./$(basename $(dirname \"$1\"))"' - {}
cd "${OLD_DIR}"

在 xcconfig 中:

DEPENDENCIES_PATH_RC         = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)
DEPENDENCIES_PATH_Release    = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)
DEPENDENCIES_PATH_T1         = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)
DEPENDENCIES_PATH_Debug      = $(SRCROOT)/../Dependencies/$(FRAMEWORKS_PATH_12_4)

DEPENDENCIES_PATH = $(DEPENDENCIES_PATH_$(CONFIGURATION))
FRAMEWORK_SEARCH_PATHS = $(inherited) $CONFIGURATION_TEMP_DIR/XCFrameworkSlices/**
于 2021-02-27T05:56:35.650 回答