我在扩展BottomSheetDialogFragment的整个类中都出错了
Cannot access 'androidx.lifecycle.HasDefaultViewModelProviderFactory' which is a supertype of 'FavoriteBottomDialogFragment'. Check your module classpath for missing or conflicting dependencies
类在app模块中,该模块实现了另外两个模块:核心和表示核心。
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
即使有错误,我也可以在设备中运行该项目。
发布于 2020-06-18 00:27:11
我今天经历了同样的问题,并且能够解决。结果发现,这个问题是模块使用的androidx.lifecycle:lifecycle-viewmodel
的预期版本与其他依赖代码中的更高版本之间的版本不匹配。
因此,在我的例子中,我的模块使用的是该模块的2.1.0版本,但依赖项之一是使用版本2.2.0。代码编译没有问题,因为gradle解决了对最新版本的依赖;然而,Android在某种程度上被这种情况搞糊涂了(并不总是,因为这并不总是发生,但有时--这不是我第一次看到这种情况)。
因此,解决方案是:在您的应用程序中找出这个库的最新版本,并更新这个模块的build.gradle
,以指向gradle正在解析的相同版本。或者:
lifecycle-viewmodel
gradlew app:dependencies
build.gradle
依赖于lifecycle-viewmodel
的结果,该版本是gradle表示正在解析的
H 214G 215
发布于 2020-10-01 15:14:53
在我的例子中(一个Android模块),AndroidStudio4.0.1,我在IDE中得到了许多与androidx.lifecycle.HasDefaultViewModelProviderFactory,相关的警告--我通过将这一行添加到build.gradle中解决了这个问题:
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
因此,build.gradle的开始变成:
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
...
发布于 2020-06-23 20:54:18
在我的例子中,问题得到了解决,在问题类的模块中添加了生命周期视图模型依赖项。
https://stackoverflow.com/questions/62285843
复制相似问题