You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

全新KMM项目commonMain模块中IDE导入标红问题求助

全新KMM项目commonMain模块中IDE导入标红问题求助

各位好,我最近碰到了个头疼的KMM项目问题,想请大伙帮忙支支招:

我用Android Studio自带的KMM模板新建了一个项目,同步完成后运行是正常的,但只要打开commonMain模块下的任意文件,里面所有的导入语句都直接标红了,就连新增的依赖也完全无法解析。

问题重现步骤:

  • 从Android Studio的KMM模板创建全新项目
  • 同步项目后运行,功能一切正常
  • 打开commonMain模块下的任何文件,发现所有导入语句均标红
  • 尝试添加新的依赖,同样无法被IDE识别解析

已经试过的解决方法(全部无效):

  • 执行IDE的Invalidate Caches / Restart操作
  • 删除本地的.idea.gradle目录后重新同步项目
  • 手动降级Gradle版本适配
  • 放弃BOM引用,直接指定Compose和Material UI的具体依赖版本

当前项目默认的版本配置:

[versions]
agp = "8.13.2"
android-compileSdk = "36"
android-minSdk = "26"
android-targetSdk = "36"
androidx-activity = "1.12.2"
androidx-appcompat = "1.7.1"
androidx-core = "1.17.0"
androidx-espresso = "3.7.0"
androidx-lifecycle = "2.9.6"
androidx-testExt = "1.3.0"
composeHotReload = "1.0.0"
composeMultiplatform = "1.9.3"
junit = "4.13.2"
kotlin = "2.3.0"
kotlinx-coroutines = "1.10.2"
material = "1.13.0"
androidx-compose-bom = "2025.12.01"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlin-testJunit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
junit = { module = "junit:junit", version.ref = "junit" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-testExt-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-testExt" }
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-espresso" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
androidx-lifecycle-viewmodelCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtimeCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
kotlinx-coroutinesSwing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }

androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
composeHotReload = { id = "org.jetbrains.compose.hot-reload", version.ref = "composeHotReload" }
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "composeMultiplatform" }
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

有没有朋友遇到过类似的情况?或者有什么其他的排查方向可以推荐给我?麻烦大家了,非常感谢!

火山引擎 最新活动