I try to use the new Dagger Android injection thing that works so far.
Now I want to extend it to my needs.
In my MainActivityModule I added a TestModule:
@Module
abstract class MainActivityModule {
@ActivityScope
@ContributesAndroidInjector(modules = arrayOf(TestModule::class))
internal abstract fun contributeMainActivityInjector(): MainActivity
}
The TestModule is really simple:
@Module
internal abstract class TestModule {
@Provides
internal fun provideTest(): String {
return "foo bar"
}
}
But I get this error: TestModule must be set
I looked into the generated source code but can't find a hint what I have to do. I searched for this at Google too but found only simple examples :-(
What have I forgotten? You can find the complete app at GitHub.
Edit
As Jeff Bowman sayed the provideTest() needs to be static. When I create a Java class like this:
@Module
public class TestModule {
@Provides
static String provide() {
return "foo bar";
}
}
it works.
So the final question: How to make this in Kotlin? This doesn't work:
@Module
internal abstract class TestModule {
companion object {
@Provides
@JvmStatic
internal fun provideTest(): String {
return "foo bar"
}
}
}
So I need another way to create a static method.