I recently converted the majority of my project to kotlin. Now I encounter several unusual errors that all seem to relate to annotation libraries. Needless to say, it didn't happen in Java.
I'll describe the cases - one in Dagger and one in Butterknife.
1.
When having 2 @Provides
methods in different models with the same name.
For example in file "FooProvider.kt" having a "provideFooOrBar" method
@Module
class FooProvider(private val view: FooActivity) {
...
@Provides @FooScope fun provideView() = view
@Provides @FooScope fun provideFooOrBar() = Foo()
}
And having another file "BarProvider.kt" with the same method name
@Module
class BarProvider(private val view: BarActivity) {
...
@Provides @BarScope fun provideView() = view
@Provides @BarScope fun provideFooOrBar() = Bar()
}
In this case, Dagger fails to generate some factory libraries and I get the following compilation error:
Error:(27, 32) error: cannot find symbol class FooProvider_ProvideFooOrBarFactory
A sample project reproducing the issue can be found at https://github.com/maxandron/DaggerIssue325
2.
This is an issue when using Butterknife. When having two @Bind
annotated variables in two different classes - One of them just fails to initialize at runtime without any compilation error!
For example if I have:
class FooActivity {
@Bind(R.id.foo) lateinit var mFoo: View
}
class NotFooActivity {
@Bind(R.id.not_foo) lateinit var mFoo: View
}
Then one of them (or both?) will just fail to initialize without any error. Causing a kotlin.UninitializedPropertyAccessException: lateinit property mFoo has not been initialized
exception to be thrown when the field is accessed.
Is it something I'm doing wrong in configuring Kotlin or is it a kotlin bug?
Thank you in advance! Ron
open class
) instead of final? I would think it would fail in Java, this exact case because there isn't a difference. Your issue with properties COULD be related to the target of the annotation, but this other case I think is you or dagger bug – Oberlandsrc/main/kotlin
in your gradle but then put your source insrc/main/java
, is that an issue? – Oberland