Rab*_*adi 5 android kotlin-multiplatform kmm
我有两个多平台模块shared以及other一个针对 Android 和 iOS 的标准多平台模板项目。
sharedcommonMain在源集中定义一个类
class SharedGreeting()
Run Code Online (Sandbox Code Playgroud)
othershared在 gradle 文件中设置为依赖如下:
val commonMain by getting {
dependencies {
implementation(project(":shared"))
}
}
Run Code Online (Sandbox Code Playgroud)
在其androidMain源集中,它尝试引用SharedGreeting某个类 fx:
class AndroidGreeter{
val foo = SharedGreeting()
}
Run Code Online (Sandbox Code Playgroud)
但无论我尝试什么,当我尝试引用共享类时都会遇到 IDE 错误,并且我必须手动添加导入语句。
不过代码编译和部署没有问题!关于我遗漏或误解的内容有什么想法吗?或者这是 KMM 中的一个错误?
gradle 文件的完整副本other:
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
}
version = "1.0"
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64()
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.1"
framework {
baseName = "other"
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":shared"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting
val androidTest by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
}
android {
compileSdk = 32
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 24
targetSdk = 32
}
}
Run Code Online (Sandbox Code Playgroud)
完整的项目源代码: https ://github.com/RabieJradi/kmm_import_error_sample
事实证明这是 KMM 中的一个错误,Jetbrains 团队已在此处实施修复https://youtrack.jetbrains.com/issue/KTIJ-22056/KMM-Cant-reference-shared-module-commonMain-source-set -来自另一个模块的类-androidMain-source-set
| 归档时间: |
|
| 查看次数: |
1967 次 |
| 最近记录: |