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

时间:2024-10-01 11:32:21

已导入以下的包:

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>")
}