AuthComponent 没有 @Subcomponent.Builder,与 @Module.subcomponents 一起使用时需要

AuthComponent doesn't have a @Subcomponent.Builder, which is required when used with @Module.subcomponents

我正在从这个站点学习 Dagger 2 https://developer.android.com/training/dependency-injection/dagger-android。我是这样创作的,

Appcomponent.java

@Singleton
@Component(modules = {AppModule.class, AuthModule.class})
public interface AppComponent {
    AuthComponent.Factory authComponent();
}

AppModule.java

@Module
public class AppModule
{}

AuthComponent.java

@FeatureScope
@Subcomponent
public interface AuthComponent {

    @Subcomponent.Factory
    interface Factory{
        AuthComponent create();
    }


}

AuthModule.java


@Module(subcomponents = AuthComponent.class)
public class AuthModule {

}

但是我得到了错误,AuthComponent doesn't have a @Subcomponent.Builder, which is required when used with @Module.subcomponents @Module(subcomponents = AuthComponent.class)我正在按照文档做。请帮我解释一下我的错误。

编辑 这是我的匕首版本。


 //di
    api 'com.google.dagger:dagger-android:2.35.1'
    api 'com.google.dagger:dagger:2.35.1'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.20'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.20'

正如预期的那样,您的代码生成器的版本为 2.20,which is before @Subcomponent.Factory was introduced in 2.22。这会导致注释处理器步骤失败,因为它是在 @Subcomponent.Factory 存在之前编写的,即使在您的项目中您可以 编译 引用它,因为您包含了 api 用于 Dagger 2.35.1。较新版本的注释处理器正确地知道检查工厂 构建器。

在任何情况下,您都不应使用与 apiimplementation 行不同版本的 annotationProcessor 行:这已导致 之前。

占位符版本 2.x no longer seems to be available,因此请将所有 dagger 行更改为相同的值 (2.35.1) 或最新值(截至 2022 年 3 月的 2.41)。

api 'com.google.dagger:dagger-android:2.35.1'
api 'com.google.dagger:dagger:2.35.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.35.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.35.1'