Hello, I have a question, for KMM iOS default buil...
# multiplatform
k
Hello, I have a question, for KMM iOS default build sourceset generates in gradle like this:
Copy code
val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
              //
            }
        }
can I achieve this processor arch separation for Android too? (androidNativeArm64?) (I'm trying to add some C static compiled library with kotlin-native cinterop)
e
https://kotlinlang.org/docs/native-target-support.html the recently-updated list of native targets on the Kotlin website shows the current Android NDK targets:
androidNativeArm32
androidNativeArm64
androidNativeX86
androidNativeX64
k
ok, thanks! Now, when I'm using list of archs like that:
Copy code
listOf(
    androidNativeArm64(),
    androidNativeArm32(),
    androidNativeX64(),
    androidNativeX86()
).forEach {
    it.binaries.framework {
        baseName = "shared"
    }
    it.compilations.getByName("main") {
        cinterops {
            val libssl by creating
        }
    }
}
I'm getting a build error :
java.lang.IllegalArgumentException: Cannot create a framework: debugFramework. Binaries of this kind are not available for target androidNativeArm64
(I unfortunately don't really know what I'm doing in regard to gradle builds)
e
binaries.framework
is only for Objective-C (macos, ios). use
binaries.sharedLib
for other platforms
k
oh, thanks for the proper tag! Can I set somewhere an option to keep on using the 'common' libs in android (in my example I'm using jvm ktor, but after adding new builds, gradle trying to look up 'cinterop-klib' by default) This is the log:
Copy code
> No matching variant of io.ktor:ktor-client-core:2.2.2 was found. The consumer was configured to find a usage of 'kotlin-cinterop' of a library, with the library elements 'cinterop-klib', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'android_arm64' but:
          - Variant 'commonMainMetadataElements' capability io.ktor:ktor-client-core:2.2.2 declares a usage of 'kotlin-api' of a library:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about its elements (required them with the library elements 'cinterop-klib')
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'android_arm64')
e
ktor depends on kotlinx.coroutines depends on kotlinx.atomicfu… none of which are currently published for androidNative :(
you can either rebuild them yourself, adding those platforms, or rely on somebody else's builds, such as https://github.com/danbrough/kotlinxtras
k
oh, so androidNative is not compatible with android-JVM stuff, ok I hope I can avoid it then, by keeping androidNative as a small lib, and put it as a lib into another project (I really hope there is no traps in this approach)
k
Thank you for the help, you're the best kotlin Tachikoma
e
@kitto I recently posted an article about how to add c/c++ code to your Kotlin Multiplatform shared library it was very much inspired by Cashapp’s Zipline project Please take a look, I believe for Android is better to use Android NDK from android plugin for native code and not to use Android Native targets in KMM. Very simple example you can find in the repo.
127 Views