Ayoub Benzahia
Ayoub Benzahia

Reputation: 363

<identifier> expected android Hilt

I would like to try Hilt DI in my app

I done all the steps to add Hilt to my App but my problem is hilt show me error in My BaseFragment says :

error: expected topLevelClass = BaseFragment<T, D>.class ^error: [Hilt]

and BaseFragment is simple :

@AndroidEntryPoint
abstract class BaseFragment<T : ViewModel,D : ViewDataBinding>() : Fragment() {

@Inject
lateinit var viewModel: T by viewModels()


 }

and for viewModel by viewModels() not working show me error of

Cannot use 'T' as reified type parameter. Use a class instead. Type 'Lazy' has no method 'setValue(BaseFragment<T, D>, KProperty<*>, T)' and thus it cannot serve as a delegate for var (read-write property).**

so i used Factory like i used in Dagger and it works but still my problem in

BaseFragment

I appreciate you to help me out and thanks in advance

EDIT : oppen this issues on github and they says it was a bug and they will ban @AndroidEntryPoint for base classes with type parameters –

Upvotes: 3

Views: 2977

Answers (1)

wh&#253;
wh&#253;

Reputation: 172

As I already mentioned here this might be a bug inside Hilt.

Check related github issue: https://github.com/google/dagger/issues/2042

You can fix this by moving @AndroidEntryPoint from abstract class with parameters into child class without type parameters.

Upvotes: 5

Related Questions