【发布时间】:2022-08-19 16:31:31
【问题描述】:
我正在尝试构建一个依赖于 Salesforce Mobile SDK(MobileSync 库)的 Swift 包。我还没有找到任何适用于 Salesforce 移动 SDK 的 Swift 包,所以我尝试使用 MobileSync pod。
我试过什么?
这些是我遵循的步骤
- 我创建了一个新的框架项目(我们称之为
MobileSyncSPM) - 初始化pod文件并添加
MobileSync依赖 - 我想通过从框架头文件中导入
MobileSync包来公开它的所有公共接口。所以,在框架的框架头文件(MobileSyncSPM.h文件)中,添加了MobileSync.h头文件的导入
#import <MobileSync/MobileSync.h>
- 将目标
Build Libraries for Distribution的构建设置更改为YES。 - 已归档工作区项目
xcodebuild archive \\
-workspace MobileSyncSPM.xcworkspace \\
-scheme MobileSyncSPM \\
-configuration Debug \\
-destination \'generic/platform=iOS\' \\
-archivePath \'./build/MobileSyncSPM.framework-iphoneos.xcarchive\' \\
SKIP_INSTALL=NO \\
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild archive \\
-workspace MobileSyncSPM.xcworkspace \\
-scheme MobileSyncSPM \\
-configuration Debug \\
-destination \'generic/platform=iOS Simulator\' \\
-archivePath \'./build/MobileSyncSPM.framework-iphonesimulator.xcarchive\' \\
SKIP_INSTALL=NO \\
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
- 为存档生成
XCFramework二进制文件
xcodebuild -create-xcframework \\
-framework \'./build/MobileSyncSPM.framework-iphoneos.xcarchive/Products/Library/Frameworks/MobileSyncSPM.framework\' \\
-framework \'./build/MobileSyncSPM.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/MobileSyncSPM.framework\' \\
-output \'./build/MobileSyncSPM.xcframework\'
-
我在 Swift Package 的
Sources下添加了XCFramework二进制文件。 -
在
Package.swift文件中,我尝试将XCFramework二进制文件添加为binaryTarget,如下所示-
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: \"MyUtils\",
dependencies: [
.byName(name: \"MobileSyncSPM\")
]
),
.binaryTarget(name: \"MobileSyncSPM\", path: \"Sources/MyUtils/MobileSyncSPM.xcframework\"),
.testTarget(
name: \"MyUtilsTests\",
dependencies: [\"MyUtils\"]
),
]
- 使用二进制目标成功构建 Swift 包。
当我尝试从 Swift 包中导入 XCFramework 库 (MobileSyncSPM) 时,就会出现问题。
所以在 swift 包下的 swift 文件中,如果我添加以下导入
import MobileSyncSPM
我收到错误消息
Could not build Objective-C module MobileSyncSPM
期待您提出解决问题的建议。
标签: ios swift xcode swift-package-manager xcframework