Unresolved reference DaggerApplicationComponent

余生长醉 提交于 2019-11-28 22:33:56

my solution is to add

apply plugin: 'kotlin-kapt'

and remove

kapt {
    generateStubs = true
}

Please try enabling stubs generation, this might be the reason why the class is not visible at this stage of the build process. In your build.gradle file, top level:

kapt {
    generateStubs = true
}

This helped me to fix this issue

Add this in the top of the build.gradle

apply plugin: 'kotlin-kapt'

Inside android tag add

kapt {
    generateStubs = true
}

And then replace

annotationProcessor 'com.google.dagger:dagger-compiler:2.11'

to

kapt 'com.google.dagger:dagger-compiler:2.11'

Now Rebuild the project by

Build -> Rebuild project

I've already downloaded your Github project. Thanks for sharing!

The answer for your issue is pretty simple:

Build -> Rebuild project

Dagger dependencies files will be recreated and app after would launched with any problem.

I checked already this with Android Studio 2.1.2 version. It works

you should remove

kapt {
generateStubs = true}

and add to the top of application gradle file

apply plugin: 'kotlin-kapt'

then Dagger will take care of the rest :)

Also for Java users, the solution is simply to Rebuild your project.

In my case missing kapt compiler dependency. Please make sure to have below dependency too.

kapt 'com.google.dagger:dagger-compiler:2.15'

app build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.usb.utility"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.dagger:dagger-android:2.15'
    compile 'com.google.dagger:dagger-android-support:2.15' // if you use the support libraries
    kapt 'com.google.dagger:dagger-android-processor:2.15'
    kapt 'com.google.dagger:dagger-compiler:2.15'
    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'
}

Only two steps should be required for mixed Java/Kotlin projects:

  1. Add apply plugin: 'kotlin-kapt' to the top of the build file
  2. Replace annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1' with kapt 'com.google.dagger:dagger-compiler:2.14.1'

Answer is simple :

Build -> Rebuild project

It works for me.

Add this on Top of build.gradlle

apply plugin: 'kotlin-kapt'

Add this in Dependencies

kapt 'com.google.dagger:dagger-compiler:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'

After that rebuild your project . i hope it will work. Thanks

Please try adding this to your build.gradle

android {
    dexOptions {
        incremental false
    }

EDIT: apparently a year later this can happen if you don't apply kotlin-kapt plugin. Also make sure you use kaptinstead of annotationProcessor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!