I created a component, module, annotation, and Application class to initialize the component. When you try to restart a project ( Build -> Rebuild Project ), so that Dagger 2 generates the necessary classes, it throws an error.


Component:

 @Component(modules = ApplicationComponent.class) public interface ApplicationComponent { Context context(); } 

Module:

 @Module public final class ApplicationModule { private Application mApplication; public ApplicationModule(Application application) { this.mApplication = application; } @Provides @PerApplication public Context provideContext() { return mApplication.getApplicationContext(); } } 

Annotation:

 @Scope @Retention(RetentionPolicy.SOURCE) public @interface PerApplication { } 

Application :

 public class OSLoaderApplication extends Application { private ApplicationComponent mApplicationComponent; public OSLoaderApplication() { createApplicationComponent(); } private void createApplicationComponent() { mApplicationComponent = DaggerApplicationComponent.builder() //DaggerApplicationComponent подсвечивается красным .applicationModule(new ApplicationModule(this)) .build(); } } 

Mistake:

 Information:Gradle tasks [clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugUnitTestSources, :app:compileDebugAndroidTestSources] Jack is required to support java 8 language features. Jack is required to support java 8 language features. :clean :app:clean :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2510Library :app:prepareComAndroidSupportAppcompatV72510Library :app:prepareComAndroidSupportDesign2510Library :app:prepareComAndroidSupportRecyclerviewV72510Library :app:prepareComAndroidSupportSupportCompat2510Library :app:prepareComAndroidSupportSupportCoreUi2510Library :app:prepareComAndroidSupportSupportCoreUtils2510Library :app:prepareComAndroidSupportSupportFragment2510Library :app:prepareComAndroidSupportSupportMediaCompat2510Library :app:prepareComAndroidSupportSupportV42510Library :app:prepareComAndroidSupportSupportVectorDrawable2510Library :app:prepareComAndroidSupportTransition2510Library :app:prepareDebugDependencies :app:compileDebugAidl :app:compileDebugRenderscript :app:generateDebugBuildConfig :app:mergeDebugShaders :app:compileDebugShaders :app:generateDebugAssets :app:mergeDebugAssets :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources :app:mergeDebugResources :app:processDebugManifest :app:processDebugResources :app:generateDebugSources :app:mockableAndroidJar :app:preDebugUnitTestBuild UP-TO-DATE :app:prepareDebugUnitTestDependencies :app:preDebugAndroidTestBuild UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl :app:processDebugAndroidTestManifest :app:compileDebugAndroidTestRenderscript :app:generateDebugAndroidTestBuildConfig :app:mergeDebugAndroidTestShaders :app:compileDebugAndroidTestShaders :app:generateDebugAndroidTestAssets :app:mergeDebugAndroidTestAssets :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources :app:mergeDebugAndroidTestResources :app:processDebugAndroidTestResources :app:generateDebugAndroidTestSources :app:incrementalDebugJavaCompilationSafeguard :app:compileDebugJavaWithJavac D:\Projects\OSLoader\OSLoaderClient\app\src\main\java\com\rostislav\dugin\osloader\app\dependencies\ApplicationComponent.java Error:(8, 8) error: com.rostislav.dugin.osloader.app.dependencies.ApplicationComponent is listed as a module, but is not annotated with @Module Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details. Information:BUILD FAILED Information:Total time: 16.752 secs Information:2 errors Information:0 warnings Information:See complete output in console app: generateDebugSources,: app: mockableAndroidJar,: app: prepareDebugUnitTestDependencies,: app: generateDebugAndroidTestSources,: app: compileDebugSources,: app: compileDebugUnitTestSources,: app: compileDebugAndroidTestSources] Information:Gradle tasks [clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugUnitTestSources, :app:compileDebugAndroidTestSources] Jack is required to support java 8 language features. Jack is required to support java 8 language features. :clean :app:clean :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2510Library :app:prepareComAndroidSupportAppcompatV72510Library :app:prepareComAndroidSupportDesign2510Library :app:prepareComAndroidSupportRecyclerviewV72510Library :app:prepareComAndroidSupportSupportCompat2510Library :app:prepareComAndroidSupportSupportCoreUi2510Library :app:prepareComAndroidSupportSupportCoreUtils2510Library :app:prepareComAndroidSupportSupportFragment2510Library :app:prepareComAndroidSupportSupportMediaCompat2510Library :app:prepareComAndroidSupportSupportV42510Library :app:prepareComAndroidSupportSupportVectorDrawable2510Library :app:prepareComAndroidSupportTransition2510Library :app:prepareDebugDependencies :app:compileDebugAidl :app:compileDebugRenderscript :app:generateDebugBuildConfig :app:mergeDebugShaders :app:compileDebugShaders :app:generateDebugAssets :app:mergeDebugAssets :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources :app:mergeDebugResources :app:processDebugManifest :app:processDebugResources :app:generateDebugSources :app:mockableAndroidJar :app:preDebugUnitTestBuild UP-TO-DATE :app:prepareDebugUnitTestDependencies :app:preDebugAndroidTestBuild UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl :app:processDebugAndroidTestManifest :app:compileDebugAndroidTestRenderscript :app:generateDebugAndroidTestBuildConfig :app:mergeDebugAndroidTestShaders :app:compileDebugAndroidTestShaders :app:generateDebugAndroidTestAssets :app:mergeDebugAndroidTestAssets :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources :app:mergeDebugAndroidTestResources :app:processDebugAndroidTestResources :app:generateDebugAndroidTestSources :app:incrementalDebugJavaCompilationSafeguard :app:compileDebugJavaWithJavac D:\Projects\OSLoader\OSLoaderClient\app\src\main\java\com\rostislav\dugin\osloader\app\dependencies\ApplicationComponent.java Error:(8, 8) error: com.rostislav.dugin.osloader.app.dependencies.ApplicationComponent is listed as a module, but is not annotated with @Module Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details. Information:BUILD FAILED Information:Total time: 16.752 secs Information:2 errors Information:0 warnings Information:See complete output in console 

Why does Dagger 2 recognize the component as a module and how to fix it?

  • Can he add annotation? - Yuriy SPb
  • @Yuriy SPb, added, but did not help. - user189127

1 answer 1

Instead of ApplicationModule write ApplicationComponent

 @Component(modules = ApplicationComponent.class) public interface ApplicationComponent { Context context(); } 
  • Hmm ... Indeed, did not notice. - user189127