小编Rab*_*adi的帖子

Kotlin Multiplatform:无法从另一个模块的 androidMain 源集中引用 commonMain 源集中的类

我有两个多平台模块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 …
Run Code Online (Sandbox Code Playgroud)

android kotlin-multiplatform kmm

5
推荐指数
1
解决办法
1967
查看次数

标签 统计

android ×1

kmm ×1

kotlin-multiplatform ×1