I遵循Kotlin文档以添加iOS依赖性。 就我而言,依赖性是通过第三方提供的预编译框架。 因此,我遵循了没有可可录的框架。
I将我的myframework.def文件放在 /src中
language = Objective-C
modules = MyFramework
package = MyFramework
然后我将以下内容添加到kotlin对象中的build.gradle.kts
````'
ios {
binaries {
framework {
baseName = "shared"
}
}
}
iosArm64() {
compilations.getByName("main") {
val JWBLe by cinterops.creating {
// Path to .def file
defFile("src/nativeInterop/cinterop/MyFramework.def")
compilerOpts("-framework", "MyFramework", "-F/Users/user/Projects/MyFramework/ios/SDK")
}
}
binaries.all {
// Tell the linker where the framework is located.
linkerOpts("-framework", "MyFramework", "-F/Users/user/Projects/MyFramework/ios/SDK")
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.1")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13")
}
}
val iosMain by getting
val iosTest by getting
}
然后我构建了该项目。 图书馆的确确实被看到了,我看到在外部库中,有一个shared-cinterop-MyFramework.klib
src/iosMain/kotlin/com.example.testapp.shared/platform.kt
时 我遇到了库的错误错误。 似乎我还需要在源组中添加一些东西吗?但是我不确定。首先,我要注意到Gradle脚本不正确。在这种情况下,
,然后再一次配置cinterop。为了避免这种重复,最好像这样配置cinterop:
ios()
val iosArm = targets.getByName("iosArm64") as org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
// A bit dirty cast, but as I'm sure iosArm64 is the Native target, it should be fine. Needed to make highlighting below work as expected.
iosArm.apply {
compilations.getByName("main") {
val JWBLe by cinterops.creating {
// Path to .def file
defFile("src/nativeInterop/cinterop/MyFramework.def")
compilerOpts("-framework", "MyFramework", "-F/Users/user/Projects/MyFramework/ios/SDK")
}
}
binaries.all {
// Tell the linker where the framework is located.
linkerOpts("-framework", "MyFramework", "-F/Users/user/Projects/MyFramework/ios/SDK")
}
}
,但是,这种调整无助于访问iosMain
cintop绑定。在当前的Commonizer的当前状态下,它只能共享
平台库
。因此,无论如何,将这些绑定到
src/iosArm64Main
文件夹中的所有代码是目前可用的最佳选择。在这里,从官方跟踪器到投票并订阅 - 用户定义的库的suppulport commonization。
之后,我找到了答案。为iOSMAIN无法使用的iosarm64模块设置了依赖项。 I创建了另一个文件夹SRC/iosarm64main,并将源文件放置在此处。 那时它能够解决库。 thanks to thishisthis this this this我不生成文件的问题是固定的。 但是,我的情况不需要创建一个目录。我刚刚创建了一个
src/iosArm64Main
iosMain