简体   繁体   English

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

[英]Missing components in material google library on Android

I am trying to use SwitchMaterial component within an Android project, however Android studio cannot find it at design time, and including it within my xml layouts causes a ClassNotFoundException at runtime.我正在尝试在 Android 项目中使用SwitchMaterial组件,但是 Android 工作室在设计时找不到它,并且在我的 xml 布局中包含它会在运行时导致ClassNotFoundException

  • Recent Android studio project so is already setup using AndroidX最近的 Android 工作室项目所以已经使用 AndroidX 设置
  • 'com.google.android.material:material:1.0.0' is in my dependencies and gradle syncs with no errors 'com.google.android.material:material:1.0.0'在我的依赖项中,并且 gradle 同步没有错误
  • Some other Material components are present, eg I am using MaterialButton on the same XML/Activity存在一些其他材料组件,例如我在同一个 XML/Activity 上使用MaterialButton
  • Unable to find com.google.android.material.switchmaterial.SwitchMaterial in xml在 xml 中找不到com.google.android.material.switchmaterial.SwitchMaterial
  • Unable to import com.google.android.material.switchmaterial.SwitchMaterial when trying to add to activity java unit尝试添加到活动 java 单元时无法导入com.google.android.material.switchmaterial.SwitchMaterial
  • Build settings: Compile SDK = 29 Build Tools = 29.0.2 Min SDK = 19 Target SDK = 29构建设置:编译 SDK = 29 构建工具 = 29.0.2 最小 SDK = 19 目标 SDK = 29
  • There are no proguard rules setup (At all) so should not be messing with it没有设置proguard规则(根本)所以不应该弄乱它
  • Spent an hour googling answers - nothing on SO, or the Android / Material Docs花了一个小时在谷歌上搜索答案 - 没有关于 SO 或 Android / Material Docs

Cannot find SwitchMaterial even though other components are there即使有其他组件也找不到SwitchMaterial缺少组件

app build.gradle应用程序 build.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'
}

XML layout XML布局


        <com.google.android.material.switchmaterial.SwitchMaterial
            android:id="@+id/login_notificationsSwitchFamily"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/margin_10"
            android:checked="true"
            android:text="Family Friendly"
            android:textSize="@dimen/textSize_16" />

Any help is appreciated.任何帮助表示赞赏。 I cannot see why there would be missing components.我不明白为什么会缺少组件。

You need the version 1.1.0 of the material components library.您需要材料组件库的1.1.0版本。

Currently目前

 implementation 'com.google.android.material:material:1.1.0'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android中的竖直slider使用google素材库 - Vertical slider in android using google material library 如何解决 Android Studio 中缺少的 androidx 组件? - How to resolve missing androidx components in Android Studio? Android - Material Design 中的 TextView 使用支持库 - Android - TextView in Material Design using Support Library Xamarin应用缺少com.google.android.things.jar支持库 - Xamarin app missing com.google.android.things.jar support library 谷歌材料设计库错误程序类型已经存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy - Google material design library error Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy Google Tasks API Java库中缺少API - Missing APIs in Google Tasks API Java library 无法解决:com.google.android.material.material:1.0 - Failed to resolve: com.google.android.material.material:1.0 Android:动态初始化整数数组:材质对话框库 - Android : Dynamically Initialize Integer Array : Material Dialog Library Google Cloud Talent API - Java:库缺失或示例已过时? - Google Cloud Talent API - Java: Library Missing or example outdated? 充气错误 class com.google.android.material.slider.Slider - Error inflating class com.google.android.material.slider.Slider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM