问题描述
我正在尝试将 dagger hilt 包含到我只有三个模块(app、frameworks_and_drivers、interface_adapters)的多模块项目中。我遵循了 hilt 文档 https://developer.android.com/training/dependency-injection/hilt-android?hl=es-419,所以我结束了向三个不同模块添加相同的内容,我知道我们可以简化为只添加一个。当我尝试重建项目时出现此错误:“错误:找不到符号 导入 dagger.hilt.android.components.ApplicationComponent;"
由于某种原因,即使其他应用程序组件可用,应用程序组件也不可用。
解决方法
从 2.33-beta
开始没有应用程序组件,您将不得不使用 SingletonComponent。 docs 在这里。
我找到了更新 build.gradle (Project) classpath 'com.google.dagger:hilt-android-gradle-plugin:2.31.2-alpha'
中的 hilt 版本并更新 build.gralde (your_module) **"
// DI with Hilt
implementation "com.google.dagger:hilt-android:2.31.2-alpha"
kapt "com.google.dagger:hilt-compiler:2.31.2-alpha"
implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03
'"** 这是对我有帮助的视频:https://youtu.be/9ZnzmbClarw