我正在尝试编译https://github.com/svenjacobs/android-dagger2-example 但我遇到了与未作用域组件相关的错误,具体取决于作用域组件。(Android Studio 1.1、Gradle 2.2.1)。此外,如果有人知道其他带有片段的 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();
}