kapt Build Fails With Dagger Android Processor

Bah, I missed part of the error message that was before the break:

:app:kaptDebugKotlin
e: /Users/me/Downloads/App/app/build/tmp/kapt3/stubs/debug/com/example/app/ui/module/main/MainActivityModule.java:10: error: @dagger.android.ActivityKey methods should bind dagger.android.AndroidInjector.Factory<? extends android.app.Activity>, not dagger.android.AndroidInjector.Factory<? super android.app.Activity>. See google.github.io/dagger/android
e: 

e:     public abstract dagger.android.AndroidInjector.Factory<? super android.app.Activity> bindMainActivityInjectorFactory(@org.jetbrains.annotations.NotNull()
e:                                                                                          ^

w: warning: The following options were not recognized by any processor: '[kapt.kotlin.generated]'
w: 


e: /Users/me/Downloads/App/app/src/main/kotlin/com/example/app/ApplicationComponent.kt: (1, 1): Some error(s) occurred while processing annotations. Please see the error messages above.

I was using the in variance annotation instead of the out annotation when creating the AndroidInjector.Factory.

@Module(subcomponents = arrayOf(MainActivitySubcomponent::class))
abstract class MainActivityModule {

    @Binds @IntoMap @ActivityKey(MainActivity::class)
    abstract fun bindMainActivityInjectorFactory(
            builder: MainActivitySubcomponent.Builder): AndroidInjector.Factory<out Activity> // Was using `in` annotation instead of `out`
}

I think the problem is related to the kotlin-stdlib-jre7, it doesn't work properly with dagger, I suggest you change this kotlin-stdlib-jre7 for kotlin-stdlib :

compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.2"

instead of:

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2"

it works for me.


I went through the same problem. I had to take off from my build.gradle:

  1. apply plugin: 'kotlin-kapt'
  2. kapt 'groupId:artifactId:$kapt_version'

And I added this (straight away after apply plug:....):

kapt {
    generateStubs = true
}

I hope this could help someone else.