【问题标题】:Building a Swift Package with Salesforce Mobile SDK dependency使用 Salesforce 移动 SDK 依赖项构建 Swift 包
【发布时间】: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


    【解决方案1】:

    您的MobileSyncSPM.xcframework 中有module.modulemap 文件吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 2018-04-29
      • 2016-03-24
      • 1970-01-01
      相关资源
      最近更新 更多