Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hilt integration crashes application MainActivity_GeneratedInjector

Trying to integrate hilt using android Api Documentation but app crashed with following exception. https://developer.android.com/training/dependency-injection/hilt-android

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.package.application/com.package.application.MainActivity}: 

java.lang.ClassCastException: com.package.application.DaggerAppApplication_HiltComponents_ApplicationC$ActivityRetainedCImpl$ActivityCImpl 
cannot be cast to com.package.application.MainActivity_GeneratedInjector

   
like image 857
Vishal Pawar Avatar asked Sep 11 '25 02:09

Vishal Pawar


1 Answers

What worked for me:

  1. Removed the @AndroidEntryPoint annotation from the activity.
  2. Ran the code and of course, it failed.
  3. Had a fragment inside the activity. So, I deleted the fragment code as well.
  4. Ran the code, it failed.
  5. Added the @AndroidEntryPoint annotation to the activity again.
  6. Ran the code. It ran and the error disappeared.
like image 148
a fair player Avatar answered Sep 12 '25 18:09

a fair player