迁移到androidx后,BottomNavigationView充气错误

8

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

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类文件为只读文件,因此我无法对其进行编辑。

gradle:

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格式?我如何对所有其他类也进行此操作?

1个回答

12

添加此依赖项:

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


1
以下是需要更新的所有软件包名称列表,以便迁移到AndroidX:https://developer.android.com/jetpack/androidx/migrate - Gene Bo
@GeneBo material.io 不再直接与 androidx 相关联;即使它是包 android.support.design 的继承者,现在它有了自己的命名空间。 - Martin Zeitler
我已经意识到这些更新(AndroidX等)两天了,因为我之前一直在使用早期的API版本。尝试将一个已建立的代码库(在过去的1-2年中编写)成功升级到AndroidX似乎与您在帖子中分享的内容相关。对我来说,这是让“升级大修”工作的一步。不确定,因为这对我来说是新领域,但它似乎至少处于相关的上下文中。如果有其他人第一次发现AndroidX并尝试使现有代码正常工作,我在此添加了注释。感谢您的洞察力。 - Gene Bo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接