无法访问“FavoriteBottomDialogFragment"的超类型“androidx.lifecycle.HasDefaultViewModelProviderFactory".检查你的模块分类

Cannot access #39;androidx.lifecycle.HasDefaultViewModelProviderFactory#39; which is a supertype of #39;FavoriteBottomDialogFragment#39;. Check your module cla(无法访问“FavoriteBottomDialogFragment的超类型“androidx.lifecycle.HasDefaultViewModelProviderFactory.检查你

本文介绍了无法访问“FavoriteBottomDialogFragment"的超类型“androidx.lifecycle.HasDefaultViewModelProviderFactory".检查你的模块分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在扩展 BottomSheetDialogFragment 的整个类中遇到错误

I am getting error in the whole class that extends BottomSheetDialogFragment

Cannot access 'androidx.lifecycle.HasDefaultViewModelProviderFactory' which is a supertype of 'FavoriteBottomDialogFragment'. Check your module classpath for missing or conflicting dependencies

该类在 app 模块中,该模块实现了另外两个模块:core 和presentation-core

The class is in app module and this module implements two other modules : core and presentation-core

build.gradle

build.gradle

dependencies {

     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation project (':core')
     implementation project (':presentation-core')

     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
     implementation 'androidx.appcompat:appcompat:1.1.0'
     implementation 'androidx.core:core-ktx:1.2.0'
     testImplementation 'junit:junit:4.12'
     implementation "com.google.android.material:material:1.1.0"

     //Rx
     implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
     implementation "io.reactivex.rxjava2:rxjava:2.2.9"
     //Architecture component
     implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
     implementation 'androidx.room:room-runtime:2.0.0'
     kapt 'androidx.room:room-compiler:2.0.0'
     kapt 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
     implementation 'androidx.room:room-rxjava2:2.0.0'
     implementation 'androidx.room:room-guava:2.0.0'

     implementation 'androidx.recyclerview:recyclerview:1.1.0'
     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
 }

核心依赖

dependencies {
     api fileTree(dir: 'libs', include: ['*.jar'])
     api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61"
     api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4"
     api 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
     //library to serialize Java Objects between Contexts
     implementation 'org.parceler:parceler-api:1.1.11'
     kapt 'org.parceler:parceler:1.1.11'

     //testing dependencies
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
     testImplementation "org.mockito:mockito-core:2.24.5"
     androidTestImplementation "org.mockito:mockito-android:2.24.5"

     //architecture component
     implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
     implementation "androidx.lifecycle:lifecycle-livedata:2.0.0"

     //RxJava2
     implementation "io.reactivex.rxjava2:rxjava:2.2.9"
     implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
}

演示核心

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
}

BottomSheetDialogFragment

即使出现错误,我也可以在设备中运行项目

Even with errors i got, I can run the project in a device

推荐答案

我今天遇到了同样的问题,并且能够解决.原来问题是失败"类所在的模块使用的 androidx.lifecycle:lifecycle-viewmodel 的预期版本与 later 版本之间的版本不匹配一些其他的依赖代码.

I experienced this exact same problem today, and was able to solve. Turns out the issue was a version mismatch between the expected version of androidx.lifecycle:lifecycle-viewmodel used by the module where the "failing" class is and a later version in some other dependent code.

所以在我的例子中,我的模块使用的是该模块的版本 2.1.0,但其中一个依赖项使用的是版本 2.2.0.代码编译不会有问题,因为 gradle 将依赖解析为最新版本;然而,Android Studio 不知何故被这种情况弄糊涂了(并非总是如此,因为这种情况不会一直发生,但有时——这不是我第一次看到这种情况.)

So in my case, my module was using version 2.1.0 of this module, but one of the dependencies was using version 2.2.0. The code will compile no problem, because gradle resolves the dependency to the latest version; however Android Studio is somehow confused by this situation (not always, because this doesn't happen all the time, but sometimes – this isn't the first time I've seen this.)

因此解决方案是:找出该库的最新版本在您的应用中,并更新您的 build.gradle 以使该模块指向 gradle 正在解析的相同版本.或者:

Therefore solution is: figure out what the latest version of this library is in your app and update your build.gradle for this module to point to the same version that gradle is resolving to. Or:

  1. 运行 gradlew app:dependencies
  2. 在结果中搜索 lifecycle-viewmodel
  3. 更新您的应用中的 build.gradle 以依赖 lifecycle-viewmodel 使用 gradle 表示它正在解析的版本
  4. 将项目与 gradle 文件同步
  1. run gradlew app:dependencies
  2. search the result for lifecycle-viewmodel
  3. update build.gradle in your app to depend on lifecycle-viewmodel with the version that gradle says it is resolving to
  4. Sync project with gradle files

这篇关于无法访问“FavoriteBottomDialogFragment"的超类型“androidx.lifecycle.HasDefaultViewModelProviderFactory".检查你的模块分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法访问“FavoriteBottomDialogFragment"的超类型“androidx.lifecycle.HasDefaultViewModelProviderFactory".检查你的模块分类

基础教程推荐