Hi, I am developing a kotlin multiplatform mobile ...
# ios
f
Hi, I am developing a kotlin multiplatform mobile library for iOS and Android. On iOS the KMM library should use some functionality provided in a C++ library (
pod_mycpplibrary
). To integrate the C++ library we created a cocoapod and want to use the cinterop with ObjectiveC for interoperability with kotlin. The simplified
build.gradle.kts
looks like:
Copy code
plugins {
        kotlin("native.cocoapods")
...
kotlin {
  cocoapods {
        version = "0.0.1"
        summary = "my library"
        homepage = ""
        name = libName

        ios.deploymentTarget = "13.5"

        xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = NativeBuildType.DEBUG
        xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = NativeBuildType.RELEASE

        framework {
            baseName = libName
            isStatic = true
            transitiveExport = true
        }

        pod("pod_mycpplibrary") {
            version = "1.0"
            headers = "foo.h"
            source = path(project.file("../pod_mycpplibrary"))

        }
        useLibraries()
    }

    val xcFramework = XCFramework(libName)
    val iosTargets = listOf(
        iosArm64(),
        iosSimulatorArm64()
    )

    iosTargets.forEach {
        it.binaries{
            framework {
                baseName = libName
                xcFramework.add(this)
            }
        }
    }

    sourceSets {
...
The folder strucure is as following: • kmmproject ◦ mylib ▪︎ src ▪︎ build.gradle.kts ◦ pod_mycpplibrary ▪︎ src ▪︎ pod_mycpplibrary.podspec ◦ … The pod can be successfully created with the command
./gradlew podPublishXCFramework
and can be found in
./mylib/build/cocoapods/publish/*
If a sample app is now using this library we always have to define both dependencies in the sample app in the Podfile.
Copy code
target 'sample_app' do
  pod 'mylib', :path => '/path/to/kmmproject/mylib/build/cocoapods/publish/debug'
  pod 'pod_mycpplibrary', :path => '/path/to/kmmproject/mylib/pod_mycpplibrary'
end
Is there a way to build
mylib
in a way that we do not need to provide
pod_mycpplibrary
?
pod_mycpplibrary
is already build as static lib (
useLibraries
and
isStatic=true
). Should this not be enough? The generated podspec in the buildfolder also does not use https://guides.cocoapods.org/syntax/podspec.html#vendored_libraries Is there a way to set this? Or is there a better way to include a C++ library than using a pod with Objective C wrapper? Thank you.