Я создал компонент, модуль, аннотацию и класс Application
, для инициализации компонента. При попытке перезагрузить проект (Build -> Rebuild Project), чтобы Dagger 2 сгенерировал необходимые классы, выбивает ошибку.
Компонент:
@Component(modules = ApplicationComponent.class)
public interface ApplicationComponent {
Context context();
}
Модуль:
@Module
public final class ApplicationModule {
private Application mApplication;
public ApplicationModule(Application application) {
this.mApplication = application;
}
@Provides @PerApplication
public Context provideContext() {
return mApplication.getApplicationContext();
}
}
Аннотация:
@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();
}
}
Ошибка:
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
Почему Dagger 2 распознает компонент, как модуль и как это исправить?