首页 > 解决方案 > 无法在 Jetpack 示例应用中为 ViewPager 充气

问题描述

我克隆了 Sunflower 示例应用程序(https://github.com/googlesamples/android-sunflower)作为学习的基线结构(我显然是新人)。我想使用 ViewPager,它给出了以下运行时错误:

android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.v4.view.ViewPager
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.v4.view.ViewPager
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.ViewPager" on path: DexPathList[[...

我已经尝试对我的 gradle 文件进行大量更改以根据搜索解决此问题,但没有找到任何可行的方法。以下是当前的依赖项:

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
implementation "android.arch.navigation:navigation-fragment-ktx:$rootProject.navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$rootProject.navigationVersion"
implementation("android.arch.work:work-runtime-ktx:$rootProject.workVersion") {
    exclude group: 'com.google.guava', module: 'listenablefuture'
}

implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
implementation "androidx.legacy:legacy-support-v4:$rootProject.supportLibraryVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleVersion"
implementation "androidx.recyclerview:recyclerview:$rootProject.supportLibraryVersion"
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "com.google.android.material:material:$rootProject.supportLibraryVersion"
implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"

谁能告诉帮助指出我错过了什么?谢谢。

标签: androidgradle

解决方案


推荐阅读