【问题标题】:BottomNavigationView inflate error after migrating to androidx迁移到 androidx 后,BottomNavigationView 膨胀错误
【发布时间】:2018-12-26 20:06:10
【问题描述】:

当我尝试启动我的应用程序时,我的 Mainactivity 在 "setContentView(R.layout.activity_main);" 的 oncreate() 方法中抛出此错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sanchez.worldgramproject/com.example.sanchez.worldgramproject.Fragments.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView

迁移到androidx后出现此错误,经过进一步检查,我注意到Bottomnavigationview类中的导入语句已过时(不是androidx格式,而是旧格式)。 Bottomnavigationview 类文件是只读的,所以我不能编辑它。

分级:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example.sanchez.worldgramproject"
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 0
        versionName "0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
}



dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.github.madrapps:pikolo:1.1.6'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation'com.firebaseui:firebase-ui-storage:2.3.0'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.6'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    testImplementation 'junit:junit:4.12'

}


apply plugin: 'com.google.gms.google-services'

完整的堆栈跟踪:https://pastebin.com/Yfek0YCH

有什么方法可以更改所有导入语句以适应新的 androidx 格式?以及如何为所有其他课程做到这一点?

【问题讨论】:

    标签: android androidx appcompatactivity


    【解决方案1】:

    添加这个依赖:

    dependencies {
        // https://mvnrepository.com/artifact/com.google.android.material/material
        implementation "com.google.android.material:material:1.0.0"
    }
    

    并使用com.google.android.material.bottomnavigation.BottomNavigationView

    【讨论】:

    • 这里列出了所有要更新的软件包名称,以便转移到 AndroidX:developer.android.com/jetpack/androidx/migrate
    • @GeneBo material.io 不再与androidx 直接相关;即使它是包android.support.design 的继承者,同时它也有自己的命名空间。
    • 我在第 2 天知道这些更新(AndroidX 等),因为我一直在使用早期的 API 版本。尝试将已建立的代码库(过去 1-2 年编写的)成功升级到 AndroidX 似乎与您在帖子中分享的内容相关。对我来说,这是让“升级大修” 发挥作用的一步。不确定,因为这对我来说是新领域,但似乎至少在相关背景下。我在这里添加了注释,以防其他人第一次发现 AndroidX 并试图让现有代码工作。感谢您的洞察力
    猜你喜欢
    • 2019-04-09
    • 1970-01-01
    • 2020-02-23
    • 2019-06-28
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多