https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

Nicolas Demoisson

06/14/2021, 12:33 PM
I am using kotlin multiplatform v1.5.10 to build binaries for Android and iOS. I have 2 kotlin native project (a core and a client). In the core project I have a singleton (using kotlin 'object' with threadlocal annotation), which is find in the client. The problem is at the client export to Apple Framework via cocoapods plugin (v1.5.10) this singleton present in core seems not being exported and is not reachable through xcode. The module is well exported and other class are visible. I guess it's because the singleton is kind of declared as unused. Do you know how I could tell cocoapods plug-in to keep this singleton or to not remove unused code ? Many thks
m

mbonnin

06/14/2021, 12:36 PM
I'd expect singletons to be exported even if unused ? https://kotlinlang.org/docs/native-objc-interop.html#kotlin-singletons
n

Nicolas Demoisson

06/14/2021, 12:38 PM
Well if I directly import my core project, the singleton is imported. But not if I import the client (wich import the core project in its dependencies with api)
m

mbonnin

06/14/2021, 12:40 PM
Ah
That rings a bell. I've done things like this before:
Copy code
macosX64 {
        binaries {
            framework {
                export(project(":core"))
            }
        }
    }
n

Nicolas Demoisson

06/14/2021, 12:43 PM
I have tried this but the cocoapods plugin has already generated these binaries. Gradle throw an error like "binaries already exist"
Ps: it works normally when I use the client in an Android project
m

mbonnin

06/14/2021, 12:53 PM
Maybe something like
Copy code
macosX64() {
    binaries {
      (get(project.name) as org.jetbrains.kotlin.gradle.plugin.mpp.Framework).export(project("core"))
    }
  }
To configure an already existing binary
not exactly sure about what name the binary is registered under but you can print them and try to "guess" (or read the Kotlin plugin source...)
n

Nicolas Demoisson

06/14/2021, 1:08 PM
This end to sync error. I’ve tried :
Copy code
binaries {
    getFramework("DEBUG").export("com.myLib.core:Core:1.0.0")
    getFramework("RELEASE").export("com.myLib.core:Core:1.0.0")
}
this does not throw error, but it’s not working either
Without it my core code is imported, only the singleton is not ..
Seems like only my interfaces are exported
r

russhwolf

06/14/2021, 1:43 PM
You might also need to add
transitiveExport = true
to pick up declarations in the platform-specific sources and not just in common
n

Nicolas Demoisson

06/14/2021, 3:53 PM
Adding export(‘:myLibrary’) + transitiveExport made it work ! Thank you both
👍 1
3 Views