处理dagger2代码时出现kapt错误

时间:2018-02-11 08:48:35

标签: dagger-2 kapt

在ClientModule.kt

@Singleton
@Provides
fun provideClient(application: Application, configuration: OkhttpConfiguration?,
                  sslConfiguration: SSLConfiguration?, cookieJarConfiguration: CookieJarConfiguration?, builder: OkHttpClient.Builder, intercept: Interceptor,
                  interceptors: List<Interceptor>?, handler: GlobalHttpHandler?): OkHttpClient{...}

在AppModule.kt

@Singleton
@Provides
fun provideInterceptors(): List<Interceptor>? {
    return mInterceptors
}

错误消息是:

e: /Users/xiaoqidong/AndroidStudioProjects/DemoKotlin/framework/build/tmp/kapt3/stubs/debug/com/bnpparibas/framework/di/component/AppComponent.java:23: error: java.util.List<? extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method.
    public abstract okhttp3.OkHttpClient okHttpClient();
                                         ^
      java.util.List<? extends okhttp3.Interceptor> is injected at
          com.bnpparibas.framework.di.module.ClientModule.provideClient(…, interceptors, …)
      okhttp3.OkHttpClient is provided at
          com.bnpparibas.framework.di.component.AppComponent.okHttpClient()

生成的java文件从List&lt;中更改了我的函数签名,这太奇怪了。拦截&GT;列表

以下是生成的文件:

  @Override
  public OkHttpClient get() {
    return Preconditions.checkNotNull(
        module.provideClient(
            applicationProvider.get(),
            configurationProvider.get(),
            sslConfigurationProvider.get(),
            cookieJarConfigurationProvider.get(),
            builderProvider.get(),
            interceptProvider.get(),
            interceptorsProvider.get(),
            handlerProvider.get()),
        "Cannot return null from a non-@Nullable @Provides method");
  }

  public static Factory<OkHttpClient> create(
      ClientModule module,
      Provider<Application> applicationProvider,
      Provider<ClientModule.OkhttpConfiguration> configurationProvider,
      Provider<ClientModule.SSLConfiguration> sslConfigurationProvider,
      Provider<ClientModule.CookieJarConfiguration> cookieJarConfigurationProvider,
      Provider<OkHttpClient.Builder> builderProvider,
      Provider<Interceptor> interceptProvider,
      Provider<List<? extends Interceptor>> interceptorsProvider,
      Provider<GlobalHttpHandler> handlerProvider) {
    return new ClientModule_ProvideClientFactory(
        module,
        applicationProvider,
        configurationProvider,
        sslConfigurationProvider,
        cookieJarConfigurationProvider,
        builderProvider,
        interceptProvider,
        interceptorsProvider,
        handlerProvider);
  }
}

如何阻止kapt改变我的功能签名?

0 个答案:

没有答案