I've been facing this problem for 3 hours. I couldn't find any logical reason to what is happening. The problem is, Only when I use the generated Dagger
classes, and after Gradle
do the Build
every reference to these classes became red and I get the error:
Error: Unresolved reference: DaggerAppComponent
But, If I comment out every line in the App
class reference any of these generated Dagger
classes. The build process completed successfully. I tried doing clean/ rebuild/ make project. but it doesn't work.
Some information about my environment:
Build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "xxxxx"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "android.arch.lifecycle:extensions:1.1.0"
implementation "android.arch.lifecycle:viewmodel:1.1.0"
implementation "android.arch.lifecycle:livedata:1.1.0"
implementation "android.arch.persistence.room:runtime:1.0.0"
implementation "android.arch.lifecycle:runtime:1.1.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
kapt "android.arch.lifecycle:compiler:1.1.0"
kapt "android.arch.persistence.room:compiler:1.0.0"
kapt "com.google.dagger:dagger-compiler:2.8"
compile "com.google.dagger:dagger:2.8"
compile "com.google.dagger:dagger-android:2.8"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Kotlin version: ext.kotlin_version = '1.1.51'
Android Studio version: 3.0.1
dependencies section in Build.Gradle
file for the project (not the app module):
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
App
class:
class App:Application() {
private val component:AppComponent by lazy {
DaggerAppComponent.builder()
.build()
}
override fun onCreate() {
super.onCreate()
component.inject(this)
}
}
If anyone can figure out what is the problem, it would be much appreciated.
P.S. I'm still learning Dagger2
and I'm new to Kotlin
and Native
development in general. I came from C#
and Xamarin
background.