Android 上的材料谷歌库中缺少组件

Cap*_*ard 3 java android material-design material-components material-components-android

我正在尝试SwitchMaterial在 Android 项目中使用组件,但是 Android Studio 在设计时找不到它,并且将它包含在我的 xml 布局中会导致ClassNotFoundException在运行时出现问题。

  • 最近的 Android Studio 项目已使用 AndroidX 进行设置
  • 'com.google.android.material:material:1.0.0' 在我的依赖项中,gradle 同步没有错误
  • 存在其他一些 Material 组件,例如我MaterialButton在同一个 XML/Activity 上使用
  • 无法com.google.android.material.switchmaterial.SwitchMaterial在 xml 中找到
  • com.google.android.material.switchmaterial.SwitchMaterial尝试添加到活动 java 单元时无法导入
  • 构建设置:编译 SDK = 29 构建工具 = 29.0.2 最小 SDK = 19 目标 SDK = 29
  • 没有设置proguard规则(完全)所以不应该弄乱它
  • 花了一个小时的谷歌搜索答案 - 没有关于 SO 或 Android / Material Docs

SwitchMaterial即使有其他组件也找不到 缺少组件

应用程序构建.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "my.app.id"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "0.0.1"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "6g"
    }
    lintOptions {
        lintConfig file("lint.xml")
        showAll false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'
}
Run Code Online (Sandbox Code Playgroud)

XML 布局

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "my.app.id"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "0.0.1"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "6g"
    }
    lintOptions {
        lintConfig file("lint.xml")
        showAll false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.github.bumptech.glide:glide:4.10.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'
}
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。我不明白为什么会缺少组件。

Gab*_*tti 6

您需要材料组件库的1.1.0版本。

目前

 implementation 'com.google.android.material:material:1.1.0'
Run Code Online (Sandbox Code Playgroud)