向Kotlin多平台添加`.klib`库 [英] Adding a `.klib` library to kotlin multiplatform

查看:186
本文介绍了向Kotlin多平台添加`.klib`库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何导入cinterop-ted库以构建kotlin多平台构建的构建.

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

我已经创建了library.def文件并填充了它,我还生成了library.klib及其附带的文件夹. 我只是不明白如何将其导入gradle.

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.

我在Internet上浏览了所有内容,找到了对Konan的引用,我想知道这是否是我必须使用的东西,或者是否是用于类似于"Cinterop"的东西.

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'.

我查看了以下链接,但没有发现与问题的.klib import部分远程连接的任何内容.

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

链接#1(kotlinlang.org )

链接#2(github.com)

链接#3(plugins.gradle.org)

推荐答案

通常,您需要使用multiplatform插件.如果要分别构建klib,则将创建一些额外的步骤(可能).在链接2中,该平台插件已弃用. Konan是本机平台/编译器的名称.去年有一个单独的插件,但是您绝对不想使用它.

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

我正在Firestore库上工作.本机和互操作配置都存在于多平台配置中.

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}")
            }
        }
    }
}

cinterops设置def文件的位置和参数.然后,我将整个内容发布为一个多平台库.最终,真正的本地工件是一个klib,但是全部使用gradle和依赖项元数据进行管理.

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.

这篇关于向Kotlin多平台添加`.klib`库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆