https://github.com/svenjacobs/android-dagger2-exampleをコンパイルしようとしています が、スコープされたコンポーネントに応じて、スコープされていないコンポーネントに関連するエラーが発生しています。(Android Studio 1.1、Gradle 2.2.1)。また、WITH FRAGMENTS を使用した他の Dagger2 Android の例を誰かが知っている場合は、それらについて知りたいと思います。
更新: フラグメントを使用した非常に基本的な別の例を次に示します: https://github.com/gk5885/dagger-android-sample
/Users/Mac1/android-dagger2-example-master/app/src/main/java/com/svenjacobs/dagger2/ActivityComponent.java
Error:(15, 1) error: com.svenjacobs.dagger2.ActivityComponent (unscoped) cannot depend on scoped components:
@Singleton com.svenjacobs.dagger2.ApplicationComponent
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
これは、明らかにスコープが設定されていないファイル ActivityComponent です。
import dagger.Component;
/**
* Component for all activities.
*
* @author Sven Jacobs
*/
@Component(dependencies = ApplicationComponent.class,
modules = {
MainActivityModule.class,
AModule.class,
BModule.class
})
interface ActivityComponent extends AFragment.Injector, BFragment.Injector {
void inject(MainActivity activity);
void inject(AnotherActivity activity);
}
そして、スコープ付きコンポーネントは次のとおりです。
package com.svenjacobs.dagger2;
import javax.inject.Singleton;
import dagger.Component;
/**
* Application-wide dependencies.
*
* @author Sven Jacobs
*/
@Singleton
@Component(modules = ApplicationModule.class)
interface ApplicationComponent {
void inject(Dagger2Application application);
/**
* Provides dependency for sub-components
*/
SomeApplicationDependency someApplicationDependency();
}