Adding a `.klib` library to kotlin multiplatform

a 夏天 提交于 2019-12-13 03:32:42

问题


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:


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.



来源:https://stackoverflow.com/questions/57170318/adding-a-klib-library-to-kotlin-multiplatform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!