gpt4 book ai didi

gradle - 如何在Kotlin/Multiplatform项目中使用.klib库

转载 作者:行者123 更新时间:2023-12-03 05:02:58 27 4
gpt4 key购买 nike

我想在我的Kotlin / Multiplatform项目(通用级别)中使用C代码。
通过本文:
https://theprogrammershangout.com/resources/kotlin/native/creating-c-bindings.md/
我得到了.klib文件,现在我想将其添加到IntelliJ Kotlin / Multiplatform项目中。
我试图将其添加到Gradle而不成功:

implementation files("/path/to/App.klib")
项目已成功构建,但是导入的应用程序未解析。
我想念什么?
我已经在整个互联网上搜索了,没有发现任何有用的信息。
我的build.gradle:
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}

plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.4.10'
id 'maven-publish'
}

apply plugin: 'com.android.library'

repositories {
mavenCentral()
google()
jcenter()
}

group 'com.texel.examples.kotlinnative'
version '0.0.1'

android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
sourceSets {
main {
manifest.srcFile 'src/jvmMain/AndroidManifest.xml'
java.srcDirs = ['src/jvmMain/kotlin']
res.srcDirs = ['src/jvmMain/resources']
}
}
}

dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}


kotlin {
// This is for iPhone emulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
// iosX64("ios") {
// binaries {
// framework()
// }
// }

macosX64("maccos") {
binaries {
framework()
}
}

android("android") {
// you can also publish both "release" and "debug"
publishLibraryVariants("release")
}


sourceSets {
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9-native-mt"
implementation files("/Users/user/Downloads/App.klib")
}
}
jvmMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
}
}
jsMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
}
}
macosMain {
dependencies {
}
}
iosMain {
dependencies {
}
}
}

}

configurations {
compileClasspath
}
非常感谢。

最佳答案

这是官方文档:C InteropUsing C Interop and libcurl for an App(您可能更喜欢看https://github.com/JetBrains/kotlin-native/tree/master/samples/libcurl)
如我所见,gradle的设置非常不同:

   hostTarget.apply {
compilations["main"].cinterops {
val libcurl by creating {
when (preset) {
presets["macosX64"] -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include")
presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu")
presets["mingwX64"] -> includeDirs.headerFilterOnly(mingwPath.resolve("include"))
}
}
}

关于gradle - 如何在Kotlin/Multiplatform项目中使用.klib库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64410512/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com