问题
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.
回答1:
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
}
回答2:
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.
回答3:
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.
回答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'
回答5:
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
回答6:
File->InvalidateCaches/Restart worked for me
回答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"
}
回答8:
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.
回答9:
In my case none of above works.
Follow steps to generate DaggerApplicationComponent
class.
- Clean project
- Rebuild project
- Import manually by Option + Return OR Alter + Enter if you do not have Auto import on fly setting in Android studio
Done
回答10:
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'
}
回答11:
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'
回答12:
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.
回答13:
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.
回答14:
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);
}
回答15:
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.
回答16:
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.
回答17:
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
来源:https://stackoverflow.com/questions/34989984/dagger-2-sometimes-on-compiling-i-get-cannot-find-symbol-class-daggerapplicati