The app crashes as soon as it gets installed and throws the weird error above. I have annotated the activity as shown below as well as its child fragments.
@AndroidEntryPoint
class HomeActivity : AppCompatActivity() {
companion object{
lateinit var currentUser: User
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
val navController = Navigation.findNavController(this, R.id.home_nav)
val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottom_navigation)
bottomNavigationView.setupWithNavController(navController)
fetchCurrentUser()
}
Also attaching the Application class which is mandatory for every app using Hilt as per the documentation
@HiltAndroidApp
class CoreApplication:Application()
and the logcat of the crash
Caused by: java.lang.IllegalStateException: Hilt Activity must be attached to an @AndroidEntryPoint Application. Found: class androidx.multidex.MultiDexApplication
at dagger.hilt.android.internal.managers.ActivityComponentManager.createComponent(ActivityComponentManager.java:82)
at dagger.hilt.android.internal.managers.ActivityComponentManager.generatedComponent(ActivityComponentManager.java:65)
at com.example.vcare.home.Hilt_HomeActivity.generatedComponent(Hilt_HomeActivity.java:43)
at com.example.vcare.home.Hilt_HomeActivity.inject(Hilt_HomeActivity.java:62)
at com.example.vcare.home.Hilt_HomeActivity.onCreate(Hilt_HomeActivity.java:37)
at com.example.vcare.home.HomeActivity.onCreate(HomeActivity.kt:27)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
Did you declare your Application class in manifest ?
Add
<application android:name=".CoreApplication" .... />
In my case, I faced an error with implementing a repository into the ViewModel class.
I followed some fixes to resolve the errors.
Now issue with Hilt with MVVM and clean architecture are resolved!
The solution to this problem was: Declare android:name = ".CoreApplication" in your AndroidManifest.xml file, in the <application .../>tag.
For me the solution was slightly different: in my main module I only needed Hilt for the Application class, so I only added the hilt-android dependency:
implementation 'com.google.dagger:hilt-android:2.33-beta'
Which resulted in the above error message.
What I forgot was to also add the compile dependency to the app module:
kapt 'com.google.dagger:hilt-compiler:2.33-beta'
This solved the problem, as I was missing the generated class.