Dagger 2, sometimes on compiling I get "cannot find symbol class DaggerApplicationComponent"

AndroidDagger 2

Android Problem Overview


Recent after update Android Studio (2.0.7) (maybe this is the cause) sometimes when building i get that error.

Idea is that usually compilation goes well but sometimes I get dagger error.

Is possible that is problem in Dagger configuration?

Error itself:

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature. Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE :app:prepareComAndroidSupportDesign2311Library UP-TO-DATE :app:prepareComAndroidSupportMultidex101Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE :app:prepareComDaimajiaSwipelayoutLibrary120Library UP-TO-DATE :app:prepareComF2prateekRxPreferencesRxPreferences101Library UP-TO-DATE :app:prepareComGithubAakiraExpandableLayout141Library UP-TO-DATE :app:prepareComGithubAfollestadMaterialDialogsCore0842Library UP-TO-DATE :app:prepareComGithubCastorflexSmoothprogressbarLibraryCircular120Library UP-TO-DATE :app:prepareComJakewhartonRxbindingRxbinding030Library UP-TO-DATE :app:prepareComPnikosisMaterialishProgress17Library UP-TO-DATE :app:prepareComTrelloRxlifecycle040Library UP-TO-DATE :app:prepareComTrelloRxlifecycleComponents040Library UP-TO-DATE :app:prepareComWdullaerMaterialdatetimepicker211Library UP-TO-DATE :app:prepareIoReactivexRxandroid110Library UP-TO-DATE :app:prepareMeRelexCircleindicator116Library UP-TO-DATE :app:prepareMeZhanghaiAndroidMaterialprogressbarLibrary114Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:compileDebugJavaWithJavac /home/ungvas/AndroidDev/Projects/FW/paynet-android/app/src/main/java/md/fusionworks/paynet/ui/activity/BaseActivity.java:23: error: cannot find symbol import md.fusionworks.paynet.di.component.DaggerActivityComponent; ^ symbol: class DaggerActivityComponent location: package md.fusionworks.paynet.di.component /home/ungvas/AndroidDev/Projects/FW/paynet-android/app/src/main/java/md/fusionworks/paynet/PaynetApplication.java:7: error: cannot find symbol import md.fusionworks.paynet.di.component.DaggerApplicationComponent; ^ symbol: class DaggerApplicationComponent location: package md.fusionworks.paynet.di.component 2 errors

Incremental compilation of 66 classes completed in 3.719 secs. :app:compileDebugJavaWithJavac FAILED :app:compileRetrolambdaDebug

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 19.556 secs
Thanks.

Android Solutions


Solution 1 - Android

It's seems that it have something to do with incremental compilation added in Gradle 2.10

I managed to fix it adding the following command to gradle:

-Pandroid.incrementalJavaCompile=false

You can add it in Android Studio in: File | Settings | Build, Execution, Deployment | Compiler adding it as a Command line option.

edit as of 2.0.0-beta3 the plugin gives a warning telling you that this option has been added to the Gradle DSL:

android {
	compileOptions.incremental = false
}

Solution 2 - Android

Changes in 2017:

Android Studio Canary uses a newer version of Gradle and apt plugins may not work, replaced by annotationProcessor. It may fail despite the compiler warning saying that it will be removed in a future version of gradle.

Change this dependency line:

apt 'com.google.dagger:dagger-compiler:2.7'

to

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

and remove the apt plugin.

Solution 3 - Android

You need to update your version 2.11 for dagger.

Your build.gradle's dependencies block should looks like following.

dependencies {
    // Other dependencies should go here
    compile "com.google.dagger:dagger:2.11"
    annotationProcessor "com.google.dagger:dagger-compiler:2.11"
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'javax.inject:javax.inject:1'
}

Hope this helps.

Solution 4 - Android

I was using a pure Java Library module, but was using the kotlin plugin and the dagger dependencies, like this:

build.gradle

apply plugin: 'kotlin'
dependencies {
    implementation "com.google.dagger:dagger:2.22.1"
    kapt "com.google.dagger:dagger-compiler:2.22.1"
}

The error was, I missed to add the kotlin-kapt plugin. So, my build.gradle file ended up like this:

apply plugin: 'kotlin'
apply plugin: "kotlin-kapt" // make sure you added this line

dependencies {
    implementation "com.google.dagger:dagger:2.22.1"
    kapt "com.google.dagger:dagger-compiler:2.22.1"
}

Solution 5 - Android

The latest version of Dagger (2.8) is causing this error. Make sure your dependencies are as mentioned below

apt 'com.google.dagger:dagger-compiler:2.7' compile 'com.google.dagger:dagger:2.7'

Solution 6 - Android

use the same dagger version for all the dagger dependencies. worked for me.

implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"


//define version in main build.gradle
ext {
    daggerVersion = '2.11'
}

Solution 7 - Android

I had a similar problem but for different reason.
I had the problem only when trying to generate the apk. Otherwise it was working correctly.
In my case the problem was that the class was in the test directory instead of the main directory for some unknown reason, I moved it to main and it worked.
Hope it helps someone

Solution 8 - Android

File->InvalidateCaches/Restart worked for me

Solution 9 - Android

Make sure you are using Java version 1.7. Also, if something else is broken in your dagger pipeline, it will cause this error as well.

Solution 10 - Android

In my case none of above works.

Follow steps to generate DaggerApplicationComponent class.

  1. Clean project
  2. Rebuild project
  3. Import manually by Option + Return OR Alter + Enter if you do not have Auto import on fly setting in Android studio

Done

Solution 11 - Android

You probably trying to Inject a class that is not Provided. A common scenario is when you Provide an Interface and trying to inject the concrete class.

For example:

@Provides
@Singleton
IConnection getIConnection(){ return new Connection(); }

And trying to Inject it as follows:

@Inject
Connection mConnection;

Solution 12 - Android

If you have multimodule android application, then it is important that each .gradle file has kapt dependencies:

kapt "com.google.dagger:dagger-compiler:${dagger_version}"
kapt "com.google.dagger:dagger-android-processor:${dagger_version}"

Solution 13 - Android

First, add this line to the dependencies in the buildscript in the Project build.gradle file.

 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

Second, add this line at the top in the Module: app build.gradle file

apply plugin: 'com.neenbedankt.android-apt'

Solution 14 - Android

I had this issue but it was two failures during build. One was the missing component but the other was a ButterKnife @BindView couldn't find the view. Fixing this fixed the missing component. I assume any failed annotation processing will cause similar issues.

Solution 15 - Android

Try to run the application, the build will fail and you will get the option to import the classes then. This happens because dagger only imports these classes during runtime and not at compile time.

Solution 16 - Android

In my case in presenter i didn't use @Inject annotation for overridden method of data manager and etc.

 @Inject
 public RegisterPresenter(DataManager dataManager, SchedulerProvider 
             schedulerProvider, CompositeDisposable compositeDisposable) {
                super(dataManager, schedulerProvider, compositeDisposable);
}

Solution 17 - Android

Double Check your annotations everywhere for prticular component and module. Mine problem was i was using @Named in module but not defining it in the constructor.

Solution 18 - Android

Check this if you are migrating to Dagger Hilt

I was getting a similar error when trying to migrate my app from dagger.android to Dagger Hilt. Looks like the issue was an incompatibility between the library versions. What I ended up doing was to first update my current dagger.android setup to the latest release (2.28), before starting to add and configure Dagger Hilt dependencies.

Solution 19 - Android

For the instance where I received this error, the reported error was off-the-mark in that an error with DaggerMyComponent was reported, but the root cause was that -- elsewhere in the code -- I had, mistakenly, used ButterKnife's @BindView with a private view-type member; fixing this eliminated the error.

Solution 20 - Android

That's very wired problem I face it! i don't have any idea why this related to Dagger!

I use ButterKnife for binding views but some how in coding (Rush copy/paste!) i wrote two different views with same id like below (both view with fab id)

@BindView(R.id.fab)
FloatingActionButton fab;
@BindView(R.id.fab)
Toolbar toolbar;

After trying to run app throw this error on build tab

> Compilation failed; see the compiler error output for details.

And compiler error is

> error: cannot find symbol class DaggerApplicationComponent

I know it seems ridiculous but it happen to me and after fix ids my problem solved.

Fixed Code

@BindView(R.id.fab)
FloatingActionButton fab;
@BindView(R.id.toolbar)
Toolbar toolbar;

Hope to help some one.

UPDATE

Once again it happens for me after a year and it same id in RecyclerView Adapter ids

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1542447View Question on Stackoverflow
Solution 1 - AndroidDanielDiSuView Answer on Stackoverflow
Solution 2 - AndroidKablizView Answer on Stackoverflow
Solution 3 - AndroidHiren PatelView Answer on Stackoverflow
Solution 4 - AndroidJorge E. HernándezView Answer on Stackoverflow
Solution 5 - AndroidfardownView Answer on Stackoverflow
Solution 6 - Androidrajeswari ratalaView Answer on Stackoverflow
Solution 7 - AndroidPhpLouView Answer on Stackoverflow
Solution 8 - AndroidJenison GraciousView Answer on Stackoverflow
Solution 9 - AndroidHoratioView Answer on Stackoverflow
Solution 10 - AndroidHiren PatelView Answer on Stackoverflow
Solution 11 - AndroidGal RomView Answer on Stackoverflow
Solution 12 - AndroidMladen RakonjacView Answer on Stackoverflow
Solution 13 - Androids-hunterView Answer on Stackoverflow
Solution 14 - AndroidMatt GoodwinView Answer on Stackoverflow
Solution 15 - AndroidBurhan ShakirView Answer on Stackoverflow
Solution 16 - AndroidMayuresh DeshmukhView Answer on Stackoverflow
Solution 17 - AndroidArpitView Answer on Stackoverflow
Solution 18 - AndroidSevenView Answer on Stackoverflow
Solution 19 - AndroidaandothercharsView Answer on Stackoverflow
Solution 20 - AndroidRadeshView Answer on Stackoverflow