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

Sujit

10/21/2019, 7:43 PM
I've a bit of confusion with KMP build for native. I'm trying to build for iOS platforms, both sim and device (only 64 bits). So, I've it build as follows:
Copy code
val ios64 = iosArm64("ios64")
    val iosSim = iosX64("iosSim")
    val iosMain by sourceSets.creating {
        dependencies {
            implementation(kotlin(Config.ios.dependencies.stdlib))
            implementation(Config.ios.dependencies.serialization)
            implementation(Config.ios.dependencies.coroutines)
        }
    }
    val iosTest by sourceSets.creating {
        dependencies {
            implementation(kotlin(Config.ios.dependencies.stdlib))
            implementation(Config.android.dependencies.coroutinesTest)
        }
    }
    configure(listOf(ios64, iosSim)) {
        binaries.framework {
            baseName = Config.ios.frameworkName
            freeCompilerArgs.add("-Xobjc-generics")
        }
        sourceSets {
            @Suppress("UNUSED_VARIABLE")
            val ios64Main by getting {
                dependsOn(iosMain)
            }
            @Suppress("UNUSED_VARIABLE")
            val iosSimMain by getting {
                dependsOn(iosMain)
            }
            @Suppress("UNUSED_VARIABLE")
            val ios64Test by getting {
                dependsOn(iosTest)
            }
            @Suppress("UNUSED_VARIABLE")
            val iosSimTest by getting {
                dependsOn(iosTest)
            }
        }
    }
Now, when I make a publication, it publishes two separate native components for iOS, basically, for both
iossim
, and
ios64
. What's the standard way to do this, such that I can only publish the native library called
native
, and no
iossim
,
ios64
. I feel like I'm missing a link here somewhere... All the sources are in
iosMain
, and
iosTest
folders
k

Kris Wong

10/21/2019, 7:49 PM
do I understand that you want one fat framework?
s

Sujit

10/21/2019, 7:49 PM
I have a separate thing in gradle for the fat framework. I'm more about wondering on the maven publication of this library.
k

Kris Wong

10/21/2019, 7:50 PM
what artifact do you intend to publish to maven?
s

Sujit

10/21/2019, 7:50 PM
As in what artifacts for ios/native ones?
k

Kris Wong

10/21/2019, 7:51 PM
yes
s

Sujit

10/21/2019, 7:52 PM
I'm not entirely sure what I really need, but I wanna be able to use this library as a dependencies in other KMP project for native components. I've
.jar
,
.klib
, and
.pom
that it publishes for
iosSimulator
, and
iosDevice
at the moment
I'm wondering, how can I just use
native
the library published by other libraries like
serialization
,
ktor
, and so on, and what am I doing wrong because of which, I'm publishing multiple things for just
iOS
k

Kris Wong

10/21/2019, 7:55 PM
the only way I am familiar with using a native dependency is via subproject, though I get the impression it may be possible with the .klibs. perhaps someone else knows another way.
i've not seen anyone mention they got it working with maven
s

Sujit

10/21/2019, 7:57 PM
My initial impression was that, the dependencies manager asks the repo for the correct version of
klib
to download in terms of architecture when we ask
native
, but I'm not sure how I can publish that
So, then, what would be best approach for publishing it @Kris Wong? I thought maven was the way to go...
Like, I can pull the dependencies remotely for coroutines for example, like:
"org.jetbrains.kotlinx:kotlinx-coroutines-core-native:${Config.version.coroutines}"
, which works on all native platforms, without having to specify separate dependencies for
iosx64
, or
iosarm64
and so on...
k

Kris Wong

10/21/2019, 8:08 PM
i am not familiar with how to publish an MPP to use as a dependency for another MPP, though I do assume that this is working for projects like ktor and others, so you could probably learn from their source repo
s

Sujit

10/21/2019, 8:20 PM
I'm looking into those projects, and feel like that's what I'm doing. But I think my basic idea of just publishing the
klib
is wrong in itself. May be I should publish something that is architecture independent, like I do for android, which when used in other KMP project, compiles to
klib
¯\_(ツ)_/¯
r

ribesg

10/22/2019, 8:08 AM
Just let the normal KMP publication happen, it publishes everything needed, with Gradle metadata. Then in your client KMP project, you just import the “root” lib and it looks for what it needs. I think the “native” packages you’re talking about are actually “root” packages, there actually are native-ios-arm64 libs etc which gets automagically imported if needed.
Also take into account that “big” KMP libs like ktor are not always using the latest way of doing things in KMP
19 Views