从
我的
如何解决这个问题?
2.33-beta
版本迁移到2.35
版本后,我的项目停止了构建,并显示以下错误:
一个txt版本:error: cannot access DefaultActivityViewModelFactory
class file for dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory not found
我的
build.gradle
(项目)的一小部分代码:buildscript {
ext.hilt_version = '2.33-beta'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
...
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的 build.gradle
(app)的片段:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdkVersion 29
...
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation": "$projectDir/schemas".toString(),
"room.incremental" : "true"
]
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
buildFeatures {
viewBinding true
dataBinding true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
//DI
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
implementation 'androidx.hilt:hilt-work:1.0.0-beta01'
kapt "com.google.dagger:hilt-compiler:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
kapt 'androidx.hilt:hilt-compiler:1.0.0-beta01'
// INSTRUMENTED TESTS
...
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
kaptAndroidTest "com.google.dagger:hilt-android-compiler:$hilt_version"
androidTestImplementation "androidx.work:work-testing:2.5.0"
//KOTLIN
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32"
//LIFECYCLE
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
// WORK MANAGER
implementation "androidx.work:work-runtime-ktx:2.5.0"
}
如何解决这个问题?
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
。 - Rafsanjaniandroidx.hilt:hilt-lifecycle-viewmodel
依赖是问题所在。在 beta 版本中它也是多余的。请随意编写答案 ;) - Patryk Kubiak