未解决的引用:viewModels(Hilt)

3

我已经添加了依赖项,但仍然出现错误。

implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01'
kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01'

未解决的引用:viewModels。
2个回答

9
你需要添加fragment-ktxactivity-ktx
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation "androidx.activity:activity-ktx:1.1.0"

解决了我的问题。谢谢。 - Diego Farias

1

这也取决于你想如何使用依赖关系。

//to add the dependency on Fragment
implementation 'androidx.fragment:fragment-ktx:1.2.5'

//to add the dependency on the Activity
implementation 'androidx.activity:activity-ktx:1.1.0' 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接