且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Dagger 2没有生成我的组件类

更新时间:2023-09-29 16:59:04

如果您使用apt插件,如下所示

if you are using apt plugin as following

类路径'com.neenbedankt.gradle.plugins:android-apt:1.8' 应用插件:"com.neenbedankt.android-apt"

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' apply plugin: 'com.neenbedankt.android-apt'

然后包括

使用"com.google.dagger:dagger-compiler:$ DAGGER_VERSION"

以及

编译"com.google.dagger:dagger:$ DAGGER_VERSION"

在模块级别build.gradle

除了配置问题外,如果从属模块或类中存在任何错误(很可能是语法错误),则Dagger2也将无法生成Component类.

Other than config issue Dagger2 will also fail to generate the Component classes if there is any error (most probably syntax error) in the dependent module or classes.

只需打开相关类并解决问题(如果有的话),然后重新构建项目即可.

just open the dependent classes and fix the issue if any and re build the project .

一些无效的缓存也可以使用:Android Studio-> file->使缓存无效并重新启动

Some invalidating cache also works : Android Studio->file->invalidate cache and Restart