After migrating the Hilt version from 2.33-beta
to 2.35
my project has stopped building with the error given below:
A txt version:
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
A snippet of my build.gradle
(project):
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
}
A snippet of my 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"
}
How can I solve this issue?
Removing the dependency on hilt-lifecycle-viewmodel causes the error to go away as it is no longer required in newer versions of hilt.
Simply delete this line from your app level build.gradle
file if you have it.
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:x.x.x'