Yu-Hsuan
Yu-Hsuan

Reputation: 505

Nested multiplatform libraries usage with cocoapods intergration

In Android world, I could add a dependency in a module, for any module which add this module as a dependency, it could use API from that dependency as will. e.g. facebook sdk -> utils module -> foo module -> main app module, both foo module & main app module could use facebook sdk API as well.

How do I did the same thing in multiplatform world (or in iOS world)? facebook iOS sdk pod -> utils module -> foo module -> iOS main project

I've tried to add pod only in utils module, but neither foo & main could access facebook iOS API. If I add same pod in foo module, it can't access Facebook API neither.

Or should I use another dependency management tool other than cocoapods?

Upvotes: 0

Views: 718

Answers (2)

Artyom Degtyarev
Artyom Degtyarev

Reputation: 2888

I guess you would like to have something like Export dependencies to binaries in the end. However, I'm not sure this will work for dependencies between Kotlin modules. For dependencies between them, I would recommend using the api dependencies link and adding pods for each module individually.
I mean, core module's build.gradle.kts should contain only

...
kotlin {
    ios()

    cocoapods {
        ios.deploymentTarget = "13.5"

        summary = "CocoaPods test library"
        homepage = "https://github.com/JetBrains/kotlin"

        pod("FBSDKCoreKit")
    }
}
...

login module is having both cocoapods and core dependencies:

...
kotlin {
    ios()

    framework {
            // Mandatory properties
            // Configure fields required by CocoaPods.
            summary = "Some description for a Kotlin/Native module"
            homepage = "Link to a Kotlin/Native module homepage"
            // Framework name configuration. Use this property instead of deprecated 'frameworkName'
            baseName = "MyFramework"

            // Optional properties
            // (Optional) Dynamic framework support
            isStatic = false
            // (Optional) Dependency export
            export(project(":core"))
            transitiveExport = true
            // (Optional) Bitcode embedding
            embedBitcode(BITCODE)
        }
        pod("FBSDKCoreKit")
        pod("FBSDKLoginKit")
    }
...
    sourceSets {
        val iosMain by getting {
            dependencies {
                api(project(":core"))
            }
        }
    }
}

...

Upvotes: 3

Kevin Galligan
Kevin Galligan

Reputation: 17352

You can only export a single Kotlin Xcode Framework. It's kind of a "big binary" that has all of it's dependencies. If "utils module" and "foo module" are both Kotlin modules, you should collect them into a single Kotlin Xcode Framework.

Upvotes: 0

Related Questions