【发布时间】:2021-03-19 23:08:37
【问题描述】:
我已按照 Kotlin 文档添加 iOS 依赖项。就我而言,依赖项是通过第三方提供的预编译框架。所以我遵循了没有 cocoapod 的框架的案例。
我将 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
我收到图书馆未解决的错误。看来我还需要在 sourceSets 中添加一些东西?但我不确定。
【问题讨论】:
标签: kotlin kotlin-multiplatform