1

In 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{...}

In AppModule.kt

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

The error msg is:

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()

It's so weird that the generated java file changed my function signature from List< Interceptor> to List

The following is the generated file:

  @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);
  }
}

How can stop the kapt change my function signature ?

Ilya Kharabet
  • 4,203
  • 3
  • 15
  • 29
ShawnD
  • 11
  • 2
  • I don't see how your question relates to the code/error you show, and the generated code still includes the list with the generics like you specified it with Kotlin. About your error, please [see here](https://stackoverflow.com/q/44912080/1837367) for more information. – David Medenjak Feb 11 '18 at 14:21
  • to build a OkHttpClient , we need a List which was declared in the kotlin code in ClientModule.kt . Kapt would translate it into java code (plz refer to last code fragment in the post) , you can find that List was changed to List< ? extends Interceptor> . To build a component , the dagger will find List< ? extends Interceptor> in the graph , but it can't find it , because there is only List , so it reported a error that error: **java.util.List extends okhttp3.Interceptor> cannot be provided without an @Provides-annotated method.** – ShawnD Feb 12 '18 at 01:03
  • 1
    we provide the List in AppModule.kt . The last code fragment is generated by kapt from ClientModule.kt. You can find that in the **create** function , it has a parameter **Provider> interceptorsProvider** . In fact it should be **Provider> interceptorsProvider** – ShawnD Feb 12 '18 at 01:17
  • Now I get you! I think [this](https://stackoverflow.com/q/45384389/1837367) might help – David Medenjak Feb 12 '18 at 12:07
  • That's very helpful. Thank you very much – ShawnD Feb 13 '18 at 01:03

0 Answers0