android - 尝试使用 Android material3 时出现 Unresolved reference 错误

标签 android kotlin android-jetpack-compose material-components-android android-jetpack-compose-material3

我在尝试使用 Jetpack Compose 和 Material3 组件构建新的 Android 应用程序时遇到以下 Unresolved reference 错误。

enter image description here

到目前为止,我已经尝试了 this 中提到的以下步骤页:

  1. 将 android.material 的依赖更新为 1.5.04 或更高版本
  2. 确保compileSDK为31
  3. 确保使用 JAVA 8 进行编译
  4. 使用 AppCompatActivity 扩展我的 MainActivity
  5. 使缓存无效并重新启动

我的gradle代码如下:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.recoverme"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        useIR = true
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion '1.5.21'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.6.0-alpha01'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.4.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}

最佳答案

你不见了

implementation "androidx.compose.material3:material3:1.0.0-alpha02"

在你的 build.gradle 中。

Latest material3 release

关于android - 尝试使用 Android material3 时出现 Unresolved reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70502517/

相关文章:

android - 回收站 View 未正确更新

kotlin - jetpack compose 脚手架 可以覆盖 SnackBar 的标准持续时间吗?

android - 如何在 Jetpack Compose 中将 NavigationRail 的内容居中(menuGravity 缺失)

kotlin - JavaFX:在修改基础列表时更改过滤列表谓词

android - 如何提升多个状态?

java - 我可以用 Java 编写 Jetpack Compose 组件吗?

Android - Galaxy S4 和 Nexus 5 的布局

android - android 清除字符串中的值

android cordova : cordova. exec() 未定义不是一个函数

android - 是否可以在不破坏 AndroidManifest XML 的情况下重构包?