Bradley Deans
Bradley Deans

Reputation: 61

Error with Dagger Hilt in Android Project: Unable to process HiltComponents.SingletonC

I am working on an Android project that hasn't been touched in some time. The previous developer left a few years ago and did not leave any documentation. I have looked through the Hilt dependency documentation and can not find what I might be missing. I am encountering the following error when attempting to run the application:

error: ComponentProcessingStep was unable to process 'com.mrpg.mobile.app.check.App_HiltComponents.SingletonC' because 'dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory' could not be resolved.
  
  Dependency trace:
      => element (CLASS): androidx.hilt.lifecycle.ViewModelFactoryModules.ActivityModule
      => element (METHOD): provideFactory(android.app.Activity,android.app.Application,java.util.Map<java.lang.String,javax.inject.Provider<androidx.hilt.lifecycle.ViewModelAssistedFactory<? extends androidx.lifecycle.ViewModel>>>)
      => annotation: @dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory
      => type (ERROR annotation type): dagger.hilt.android.internal.lifecycle.DefaultActivityViewModelFactory

Here are the relevant gradle files:

app/build.gradle:

plugins {  
  id 'com.android.application'  
  id 'kotlin-android'  
  id 'kotlin-allopen'  
  id 'kotlin-kapt'  
  id 'androidx.navigation.safeargs.kotlin'  
  id 'dagger.hilt.android.plugin'  
}  
  
apply from: "versions.gradle"  
apply from: "configurator.gradle"  
  
android {  
  namespace 'com.mrpg.mobile.app.check'  
  compileSdkVersion build_versions.compile_sdk // 34  
  buildToolsVersion build_versions.build_tools // 34.0.0
  
  testBuildType "release"  
  
  defaultConfig {  
    applicationId "com.mrpg.mobile.app.check"   
    minSdkVersion build_versions.min_sdk // 25  
    targetSdkVersion build_versions.target_sdk // 34  
    multiDexEnabled true  
    versionCode configurator.code  
    versionName configurator.name  
  }  
  
  compileOptions {  
    sourceCompatibility build_versions.java // JavaVersion.VERSION_1_8
    targetCompatibility build_versions.java // JavaVersion.VERSION_1_8  
  }  
  
  kotlinOptions {  
    jvmTarget = build_versions.jvm // 1.8 
  }  
  
  dataBinding {  
    enable = true  
  }  
  viewBinding {  
    enable = true  
  }  
  
  composeOptions {  
    kotlinCompilerExtensionVersion '1.5.1'  
  }  
  
  kapt {  
    correctErrorTypes true  
  }  

  buildTypes {  
    debug {  
      minifyEnabled false  
      shrinkResources false  
    }  
  
    release {  
      // ... 
    }  
  }  
  dependenciesInfo {  
    // ... 
  }  
  ndkVersion build_versions.ndk  
}  
  
dependencies {  
  implementation "com.google.dagger:hilt-android:$library_versions.dagger_hilt" // 2.44  
  kapt "com.google.dagger:hilt-compiler:$library_versions.dagger_hilt" // 2.44 
  implementation "com.mrpg.mobile:pos-shared-library:$library_versions.mrpg_pos_shared"  
}

build.gradle:

buildscript {  
  apply from: "versions.gradle"  
  repositories {  
    google()  
    mavenCentral()  
    gradlePluginPortal()  
  }  
  dependencies {  
    classpath "com.android.tools.build:gradle:$plugin_versions.gradle" // 8.5.1   
    classpath "com.google.dagger:hilt-android-gradle-plugin:$plugin_versions.hilt" // 2.44  
    classpath "org.jetbrains.kotlin:kotlin-allopen:$plugin_versions.kotlin" // 2.0.10  
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$plugin_versions.kotlin" // 2.0.10  
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$plugin_versions.safe_args" // 2.7.7  
  }  
}  
  
task clean(type: Delete) {  
  delete rootProject.buildDir  
}

I've tried updating dependencies and cleaning the project, but the issue persists. Any help or guidance would be greatly appreciated!

Upvotes: 3

Views: 616

Answers (1)

Dev.Joshua
Dev.Joshua

Reputation: 31

If you are facing the same issue, Check your build.gradle file and remove this line: implementation("androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-apha03")

now re-run the project.

Upvotes: 0

Related Questions