我正在学习如何使用Dagger2。我创建了一个示例,如下代码所示。我面临的问题是Daggers自动生成的类 永远不会创建应称为“ DaggerInterfaceComponent”的文件。下面的DaggerInterfaceComponent用红色强调。
请查看下面发布的构建gradle应用。
代码:
InterfaceComponent component = DaggerInterfaceComponent.builder().objectValuesModule(new ObjectValuesModule()).build();
Object injectedObject = component.getObjectValues();
int returnedInt = injectedObject.getreturnInteger();
int returnedStr = injectedObject.getReturnString();
int returnedObj = injectedObject.getReturnObject();
分级应用
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
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'
}