'@HiltViewModel annotated class should contain exactly one @Inject annotated constructor

I keep getting this error:

public final class MainViewModel extends androidx.lifecycle.ViewModel { ^ @HiltViewModel annotated class should contain exactly one @Inject annotated constructor. [Hilt] Processing did not complete. See error above for details.

Here is my MainViewModel:

@HiltViewModel
class MainViewModel @Inject constructor(
    repository: DefaultRepository
) : ViewModel() {
    val items = repository.getItems().asLiveData()
}


Solution 1:[1]

In my case, I was specifying default values for some of my primary constructor parameters. Getting rid of the default values fixed the issue.

Solution 2:[2]

Make sure you are using this inject annotation

import javax.inject.Inject

instead of this one

com.google.inject.Inject

Solution 3:[3]

Make sure in your module you have @InstallIn(SingletonComponent::class) instead of @InstallIn(ApplicationComponentManager::class)

Solution 4:[4]

In my case the problem was that one of the packages was called "case", which is a name used by some conventions (like of SQL, or even Java).

@Atick Faisal (see comments above) had also another problem with package name, so I guess it might worth a check if you don't find the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 heyheyhey
Solution 2 AncientMethods
Solution 3 Strahinja Vu?kovi?
Solution 4 Amir Golan