Android Studio中导入了包,但无法识别 WindowSizeClass 和相关函数的问题

发布于:2024-10-09 ⋅ 阅读:(34) ⋅ 点赞:(0)

已导入以下的包:

import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass

但无法识别 WindowSizeClass,并显示错误:

org.gradle.api.InvalidUserDataException: Invalid catalog definition: - Problem: In version catalog libs, alias 'androidx-material3-window-size-class-android' is not a valid alias.


 解决办法:build.gradle.kts中引入依赖

dependencies {
    implementation("androidx.compose.ui:ui:<version>")
    implementation("androidx.compose.material:material:<version>")
    implementation("androidx.compose.runtime:runtime-livedata:<version>")
    implementation("androidx.compose.ui:ui-tooling:<version>")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:<version>")
    implementation("androidx.activity:activity-compose:<version>")
    implementation("androidx.core:core-ktx:<version>")
    implementation("androidx.compose.material3:material3-window-size-class:<version>")
}