69

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.

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
user1542447
  • 761
  • 1
  • 6
  • 9

21 Answers21

34

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
}
DanielDiSu
  • 1,139
  • 1
  • 11
  • 10
  • Hi, this is equivalent with dexOptions{incremental=false}? – user1542447 Jan 28 '16 at 13:50
  • 4
    Incremental dex and incremental build are different. Incremental dex applies to the process of building the dex file, which is a stage further down the compile process from compiling the Java code. The compiled Java .class files from the first stage are then further compiled into .dex files, [as described here](http://developer.android.com/tools/building/index.html). And there's a bit more info in [this SO question](http://stackoverflow.com/questions/26779552/what-does-the-incremental-dex-option-in-android-studio-do). – neilgmacy Feb 01 '16 at 17:22
  • 1
    Sync doesn't resolve symbol DaggerApplicationComponent but when I try to run. Gradle generate it automatically. – Qamar Mar 29 '17 at 06:57
7

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"
}
Jorge E. Hernández
  • 2,800
  • 1
  • 26
  • 50
6

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.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
  • @sud007, can you please clean and rebuild the project? – Hiren Patel Mar 30 '18 at 10:03
  • Yes buddy! I have already tried most of the solutions mentioned here. But as I understand from a couple of mentioned replies here, something else may be breaking the flow for Dagger annotation build. Will post here once resolved. – sud007 Mar 30 '18 at 10:06
5

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.

Kabliz
  • 310
  • 4
  • 12
4

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'

fardown
  • 713
  • 2
  • 12
  • 23
4

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'
}
rajeswari ratala
  • 650
  • 7
  • 14
  • Adding in the two dependencies in the middle fixed this issue for me. I’m using Kotlin and this was the only fix. Thanks. – Sakiboy Sep 05 '19 at 18:48
  • I take it back, if you’re using Kotlin (as I am), you need to use the `kapt` declaration instead of the `annotationProcessor` declarations. After changing that keyword the Dagger2 code would generate and not break an hour later. – Sakiboy Sep 06 '19 at 12:58
3

File->InvalidateCaches/Restart worked for me

Jenison Gracious
  • 486
  • 4
  • 13
  • 1
    happened to me once and I resolved it by invalidate/restart + rebuild; now it happenede for 2nd time and I found a bug in my XYZModule java file, so maybe check modules for errors, there might be some – arenaq Jan 11 '19 at 16:04
  • @arenaq: Exactly same as mine! What was that bug? when I add some lines to the my app module this error happen and when I remove that line (@Bind MyViewModel.class ...) it compiles without any error but after that produce `Cannot create an instance of ViewModel class` [error](https://stackoverflow.com/q/48605672/6576302) – C.F.G Feb 23 '23 at 18:28
2

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

PhpLou
  • 430
  • 3
  • 16
  • In my case, I had refactored the name of the package that held the class I was trying to use, but the DaggerXYZ import did not update. – Dave Jul 25 '17 at 22:30
1

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.

Horatio
  • 1,695
  • 1
  • 18
  • 27
1

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

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
1

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;
Gal Rom
  • 6,221
  • 3
  • 41
  • 33
1

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}"
Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55
0

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.

0

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.

Burhan Shakir
  • 237
  • 4
  • 11
0

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);
}
Alien
  • 15,141
  • 6
  • 37
  • 57
0

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.

Arpit
  • 297
  • 1
  • 5
  • 13
0

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.

Seven
  • 3,232
  • 1
  • 17
  • 15
0

Non of the solutions worked for me. Invalid cache restart not helped also. I've resolved this issue by following these steps:

Make sure that in your ViewModel class you have used @Inject keyword before constructor. i.e.

public class MyViewModel extends ViewModel {

...

@Inject // <--- ***
public MyViewModel ( ... ){
       ...
       }
...
}
  1. Make sure that you have created @Bind for your MyViewModel in your viewModelModul class (if you have).

By following these errors will gone!

C.F.G
  • 817
  • 8
  • 16
-1

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'
s-hunter
  • 24,172
  • 16
  • 88
  • 130
-1

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.

-2

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

Radesh
  • 13,084
  • 4
  • 51
  • 64
  • 1
    Anything that breaks compilation, e.g. problems in butterknife, dagger, databinding can show up other components that are also not generated because compilation broke, it's just common sense. You see it missing DaggerApplicationComponent because that's the first compiled/generated class it happened to look for – Nick Cardoso Apr 02 '20 at 15:47