Je construis une application qui a deux modules: le module Core, qui est une bibliothèque Android (com.android.library) et le module Application (com.android.application).Bibliothèque Android, Kotlin et Dagger2
Après avoir converti les fichiers Java en Kotlin, le projet ne compile pas, ce qui me donne une erreur que les fichiers Dagger 2 générés n'ont pas été trouvés (référence non résolue). Mais ces fichiers actuellement générés sous:
... core \ build \ produit \ source de \ KAPT \ release {my \ core \ namespace} \ DaggerBaseComponent.java
Qu'est-ce que je m manquant?
build.gradle (module Core)
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
...
android {
...
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
...
// Dagger.
kapt "com.google.dagger:dagger-compiler:2.10"
compile 'com.google.dagger:dagger:2.10'
provided 'javax.annotation:jsr250-api:1.0'
// Kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
build.gradle (Module d'application)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
...
android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
...
// Dagger.
kapt "com.google.dagger:dagger-compiler:2.10"
compile 'com.google.dagger:dagger:2.10'
provided 'javax.annotation:jsr250-api:1.0'
// Kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
de build.gradle (Projet)
buildscript {
ext.kotlin_version = '1.1.2-3'
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
ApplicationContext.kt (de mon Core Module)
class ApplicationContext : Application() {
var baseComponent: BaseComponent? = null
private set
override fun onCreate() {
super.onCreate()
initializeInjector()
}
private fun initializeInjector() {
// DaggerBaseComponent is and unresolved reference
baseComponent = DaggerBaseComponent.builder()
.appModule(AppModule(this))
.endpointModule(EndpointModule())
.build()
}
companion object {
operator fun get(context: Context): ApplicationContext {
return context.applicationContext as ApplicationContext
}
}
}