如何在KMP/CMP项目中使用Icons.Rounded.*?

移动开发 2026-07-12

我遇到了一个问题,就是在我的KMP/CMP项目中无法使用Icons.Rounded.settings,即使已经添加了实现和导入。在之前的所有Android项目中它都能工作,但在CMP中却不行。有人知道这是为什么以及我应该怎么做吗?

implementation in build.gradle.kts:

implementation("org.jetbrains.compose.material:material-icons-extended:1.10.0")

import in MainScreen.kt:

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Settings

use in MainScreen.kt:

...
Icon(
    Icons.Rounded.Settings,
    null
)

"icons" in the import, as well as "Icons" in the Icon Composable are marked as an error.

感谢你的帮助,

我 :)

解决方案

希望你们已经解决了这个问题;如果还没有,下面给出解决办法。

根据 https://youtrack.jetbrains.com/projects/CMP/issues/CMP-9684/Clarify-deprecation-message-for-materialIconsExtended,以及跟踪的社区问题 https://github.com/JetBrains/compose-multiplatform/pull/5520

结论:该制品被有意固定在版本1.7.3,更新的版本尚未发布。

解决办法:所以如果你想直接使用 Icons.Rounded.Settings,请 使用最新版本1.7.3。或者迁移到Material Symbols。

Material Icons Core版本:https://central.sonatype.com/artifact/org.jetbrains.compose.material/material-icons-core/versions

Material Icons Extended版本:https://central.sonatype.com/artifact/org.jetbrains.compose.material/material-icons-extended/versions

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章