amplitude / Amplitude-Swift

Native iOS/tvOS/macOS/watchOS SDK
MIT License
32 stars 24 forks source link

Cannot Add Amplitude to Swift Package #36

Closed seank90 closed 1 year ago

seank90 commented 1 year ago

Expected Behavior

We are trying to include Amplitude iOS as part of our package.

Current Behavior

It's not getting added when we compile the XCFramework file and is read as a missing dependency.

Steps to Reproduce

  1. Create a SwiftUI Package and Add Amplitude
  2. Try and compile the project into a XCFramework like so
xcodebuild archive \
 -scheme YOUR_PROJECT \
 -archivePath ./device/ \
 -sdk iphoneos \
 SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEFINES_MODULE=YES

xcodebuild archive \
 -scheme YOUR_PROJECT \
 -archivePath ./simulator/ \
 -sdk iphonesimulator \
 SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES DEFINES_MODULE=YES

xcodebuild -create-xcframework \
 -framework ./device.xcarchive/Products/Library/Frameworks/YOUR_PROJECT.framework \
 -framework ./simulator.xcarchive/Products/Library/Frameworks/YOUR_PROJECT.framework \
 -output ./YOUR_PROJECT.xcframework
  1. Notice how the Amplitude framework is not included in the Archive or XCFramework

Environment

liuyang1520 commented 1 year ago

Thanks for supporting Amplitude!

@seank90 , could you elaborate how you "Add Amplitude"? We have these package managers supported: https://www.docs.developers.amplitude.com/data/sdks/sdk-quickstart/#install-the-dependency_4.

seank90 commented 1 year ago

Hi @liuyang1520

This is how we added it with Swift Package

let package = Package(
    name: "mobile-sdk-ios",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "mobile-sdk-ios",
            type: .dynamic,
            targets: ["mobile-sdk-ios"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/amplitude/Amplitude-Swift", from: "0.3.0"),
        .package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.1.0"),
    ],
    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: "mobile-sdk-ios",
            dependencies: [
               "multiplatform-mobile",
                "Amplitude-Swift",
                .product(name: "Sentry", package: "sentry-cocoa")
            ],
            resources: [
                .copy("Resources/Lato-Regular.ttf"),
                .copy("Resources/Lato-Bold.ttf")
            ]
        ),
        .testTarget(
            name: "mobile-sdk-iosTests",
            dependencies: ["mobile-sdk-ios"]),
        .binaryTarget(name: "multiplatform-mobile",
                      path: "../multiplatform-mobile-sdk/build/swiftpackage/multiplatform-mobile.xcframework")
    ],
    swiftLanguageVersions: [.v5]
)

When we build and inspect the archive we get this as a result.

image

As you can see we don't have Amplitude included. Which is an issue.

liuyang1520 commented 1 year ago

Thanks @seank90 !

I just search online about the XCFramework, here are some findings:

To follow up:

seank90 commented 1 year ago

Hi @liuyang1520

Thank you for sending over the links, I'll check it out.

The issue we are facing is that we are looking to have a closed source swift package. The way we can do this is by having an XCFramework within a Swift package and setting it as a binary dependancy, this way the code is secure.

But when we try and bundle Amplitude in this framework it doesn't seem to create a .framework file from where it can be referenced.

We were using Sentry for Crash Reporting 😄

Mercy811 commented 1 year ago

Hi @seank90, would like to check in and see if this issue has been solved.

Mercy811 commented 1 year ago

Closing this as it seems to be solved.