3
votes

I'm wondering how I'd be able to import my cinterop-ted library to gradle build of the kotlin multiplatform build.

I've already created the library.def file and filled it, I also generated the library.klib and the folder that goes with it. I just don't understand how to import it into gradle.

I've looked all over internet and I found a reference to Konan and I'm wondering if that's something I have to use, or if that's something being used for something similar to 'cinterop'.

I've looked over the following links, and I haven't found anything remotely connected to the .klib import part of my question.

Link #1 (kotlinlang.org)

Link #2 (github.com)

Link #3 (plugins.gradle.org)

1
did you manage to get this working in the end? I am also created the my .klib but no Idea how to load it in. Maybe you used Gradle .interops in the end, but I've not been able to get that working yet. - Pixel
I'm pretty sure I just gave up on the project entirely. I'm not sure I ever got it working, but back in those days, Kotlin Native was still in the infancy. - MG lolenstine
I'll add an answer when I get it working tomorrow (hopefully). At the moment my Gradle won't even recognize the interops keywords. I wish I was a 6502 developer back in the 80s right now lol - Pixel
@IMlolenstine not yet. I've be made progress (see my post here stackoverflow.com/questions/66851318/…) but still working on it. I decided to keep hacking away at this problem, but also work on Kotlin/Native/JNI solution too. That way I get what I want working (albeit not with KMM) but if I do manage to get KMM working I can easily reuse my Kotlin/JNI code. I'll keep working on the KMM so hopefully will get it working at some point and update this and the other post. - Pixel
@IMlolenstine hey, I think I found a solution for my use case (C/C++ interop). Perhaps it might work for you too. Check out the comments in Artyom's answer in the linked SO question of my previous comment above 😊 - Pixel

1 Answers

1
votes

In general, you'll want to use the multiplatform plugin. If you're building a klib separately, you're creating some extra steps (probably). In Link #2 it says that platform plugin is deprecated. Konan is the name of the native platform/compiler. There was a separate plugin for that last year, but you definitely don't want to be using that.

I just created an example but it's not public yet, so this is the best one I have off hand:

https://github.com/JetBrains/kotlin-native/blob/3329f74c27b683574ac181bc40e3836ceccce6c1/samples/tensorflow/build.gradle.kts#L12

I'm working on a Firestore library. The native and interop config live in the multiplatform config.

kotlin {

    android {
        publishAllLibraryVariants()
    }
//        iosArm64()
    iosX64("ios"){
        compilations["main"].cinterops {
            firebasecore {
                packageName 'cocoapods.FirebaseCore'
                defFile = file("$projectDir/src/iosMain/c_interop/FirebaseCore.def")
                includeDirs ("$projectDir/../iosApp/Pods/FirebaseCore/Firebase/Core/Public")
                compilerOpts ("-F$projectDir/src/iosMain/c_interop/modules/FirebaseCore-${versions.firebaseCoreIos}")
            }
            firestore {
                packageName 'cocoapods.FirebaseFirestore'
                defFile = file("$projectDir/src/iosMain/c_interop/FirebaseFirestore.def")
                includeDirs ("$projectDir/../iosApp/Pods/FirebaseFirestore/Firestore/Source/Public", "$projectDir/../iosApp/Pods/FirebaseCore/Firebase/Core/Public")
                compilerOpts ("-F$projectDir/src/iosMain/c_interop/modules/FirebaseFirestore-${versions.firebaseFirestoreIos}")
            }
        }
    }
}

The cinterops sets up where the def files are and params. I then publish that whole thing as a multiplatform library. The actual native artifact is a klib ultimately, but it's all managed with gradle and dependency metadata.