Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<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 –

like image 739
Ayoub Benzahia Avatar asked Dec 06 '25 04:12

Ayoub Benzahia


1 Answers

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.

like image 128
whý Avatar answered Dec 07 '25 19:12

whý



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!