簡體   English   中英

Android 上的材料谷歌庫中缺少組件

[英]Missing components in material google library on Android

我正在嘗試在 Android 項目中使用SwitchMaterial組件,但是 Android 工作室在設計時找不到它,並且在我的 xml 布局中包含它會在運行時導致ClassNotFoundException

  • 最近的 Android 工作室項目所以已經使用 AndroidX 設置
  • 'com.google.android.material:material:1.0.0'在我的依賴項中,並且 gradle 同步沒有錯誤
  • 存在一些其他材料組件,例如我在同一個 XML/Activity 上使用MaterialButton
  • 在 xml 中找不到com.google.android.material.switchmaterial.SwitchMaterial
  • 嘗試添加到活動 java 單元時無法導入com.google.android.material.switchmaterial.SwitchMaterial
  • 構建設置:編譯 SDK = 29 構建工具 = 29.0.2 最小 SDK = 19 目標 SDK = 29
  • 沒有設置proguard規則(根本)所以不應該弄亂它
  • 花了一個小時在谷歌上搜索答案 - 沒有關於 SO 或 Android / Material Docs

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

應用程序 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布局


        <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" />

任何幫助表示贊賞。 我不明白為什么會缺少組件。

您需要材料組件庫的1.1.0版本。

目前

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM