-1

In my project, using dagger-Hilt

just by adding a new activity, it shows an error

:app:kaptDebugKotlin
    [Hilt] 
    java.lang.reflect.InvocationTargetException (no error message)

but before adding a new activity, the whole project works fine

Activity :->


@AndroidEntryPoint
class SplashScreen : AppCompatActivity() {



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)
    }
}

my build.gradle

 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
 classpath("com.google.dagger:hilt-android-gradle-plugin:2.38.1")
Sidharth
  • 79
  • 10
  • Please checkout my answer and let me know whether its working fine or not. Also update app level build.gradle in your question. Need to see how you are importing hilt libraries. – Gowtham K K Aug 18 '22 at 16:13
  • here sir project [build.gradle](https://github.com/th3kumar/Snoozz-Sleeping-Buddy/blob/master/build.gradle) , Module [build.gradle](https://github.com/th3kumar/Snoozz-Sleeping-Buddy/blob/master/app/build.gradle) , – Sidharth Aug 18 '22 at 17:09
  • hey @GowthamKK here is my whole [project](https://github.com/th3kumar/Snoozz-Sleeping-Buddy) . – Sidharth Aug 19 '22 at 09:42
  • Could you please update splash activity code in your project. I couldnt find any – Gowtham K K Aug 19 '22 at 10:12
  • I have updated my answer. Please check. It should work. – Gowtham K K Aug 19 '22 at 11:31

1 Answers1

1

I have reproduced your issue. The real problem is with versions,your kotlin version is not compatible with hilt plugin version and hilt library version. Here are the few changes you need to do.

In project build.gradle, update hilt plugin version to 2.42

    classpath("com.google.dagger:hilt-android-gradle-plugin:2.42")

In app build.gradle, update to latest versions like below.

implementation("com.google.dagger:hilt-android:2.42")
kapt("com.google.dagger:hilt-android-compiler:2.42")
kapt "androidx.hilt:hilt-compiler:1.0.0"

Hilt lifecycle module not required in latest hilt version. You should remove the below line in build.gradle and remove all androidx.hilt.lifecycle.ViewModelInject imports in your project.Other wise it will throw error

implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha02"
Gowtham K K
  • 3,123
  • 1
  • 11
  • 29