Is it possible to depend my package on a 3rd party Objc static lib (header + .a file) included as asset (Swift5.3)

Hi, I am new to creating packages and I am trying to wrap a closed source tracking library into a package to be used by our team to make a simpler interface and to prefix some organisation-specific prefixes to events and such.

The 3rd party lib consists of a number of libs, each has a .a-file and a .h file.

I'd like to provide a Swift interface where I call these libraries under the hood. I am able to make the package build and import and use the package in the main app, however the package does not seem to produce any -o files for the targets with the .a files, and I get

error: Build input files cannot be found: '(...)/Products/Debug-iphonesimulator/ACPIdentity.o', '(...)/Build/Products/Debug-iphonesimulator/ACPAnalytics.o', '(...)/Build/Products/Debug-iphonesimulator/ACPCore.o' (in target 'MyApp' from project 'MyApp')

Is this at all possible to get to work?

My package file:

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "Adobe-Wrapper",
    platforms: [
           .iOS(.v13),
       ],
    products: [
        .library(
            name: "AdobeWrapper",
            targets: [
                "AdobeWrapper",
                "ACPAnalytics",
                "ACPCore",
                "ACPIdentity"
            ]),
    ],
    dependencies: [],
    targets: [
        .target(
            name: "ACPAnalytics",
            dependencies: [],
            path: "./Sources/ACPAnalytics",
            resources: [.process("libACPAnalytics_iOS.a")],
            cSettings: [.headerSearchPath("./Sources/ACPAnalytics")]
        ),
        .target(
            name: "ACPCore",
            dependencies: [],
            path: "./Sources/ACPCore",
            resources: [.process("libACPCore_iOS.a")],
            cSettings: [.headerSearchPath("./Sources/ACPCore")]
        ),
        .target(
            name: "ACPIdentity",
            dependencies: [],
            path: "./Sources/ACPIdentity",
            resources: [.process("libACPIdentity_iOS.a")],
            cSettings: [.headerSearchPath("./Sources/ACPIdentity")]
            
        ),
        .target(
            name: "AdobeWrapper",
            dependencies: [
                .target(name: "ACPAnalytics"),
                .target(name: "ACPCore"),
                .target(name: "ACPIdentity")
            ],
            linkerSettings: [
                LinkerSetting.linkedFramework("libz.tbd"),
                LinkerSetting.linkedFramework("UIKit.framework"),
                LinkerSetting.linkedFramework("SystemConfiguration.framework"),
                LinkerSetting.linkedFramework("WebKit.framework"),
                LinkerSetting.linkedFramework("UserNotifications.framework"),
                LinkerSetting.linkedFramework("libsqlite3.0.tbd"),
                LinkerSetting.linkedFramework("libc++.tbd"),
                
            ]),
        .testTarget(
            name: "AdobeWrapperTests",
            dependencies: ["AdobeWrapper"]),
    ]
)

file structure

image

I think what you are looking for is https://developer.apple.com/documentation/swift_packages/distributing_binary_frameworks_as_swift_packages

Hi @NeoNacho, thank you! Might be, are you suggesting that I build an xcframework and wrap the library in there with headers and .a-files and subsequently import that xcframework into my package?

Yep that's where I was going, sorry my response should have been more detailed. You can wrap the libraries and headers you have using:

xcodebuild -create-xcframework [-help] [-framework <path>] [-library <path> [-headers <path>]] -output <path>

Note that one XCFramework should contain one library, just in different platform variants, so you may need to create multiple ones.

@NeoNacho Got it, thank you so much for answering!

Terms of Service

Privacy Policy

Cookie Policy