问题描述
我已经创建了一个演示的Android库项目,并用匕首2.0以下步骤:
I have created a demo Android Lib project and used dagger 2.0 with the following steps:
-
增加了以下罐子/ libs文件夹:
Added the following jars to /libs folder:
匕首2.0.jar
匕首编译-2.0.jar
dagger-compiler-2.0.jar
匕首生产者-2.0-beta.jar
dagger-producers-2.0-beta.jar
番石榴18.0.jar
guava-18.0.jar
javawriter-2.5.1.jar
javawriter-2.5.1.jar
javax.annotation中-API-1.2.jar
javax.annotation-api-1.2.jar
javax.inject-1.jar
javax.inject-1.jar
项目 - >属性 - > Java编译器 - >注释处理(启用标注处理)
Project -> Properties -> Java Compiler -> Annotation Processing (Enabled annotation processing)
项目 - >属性 - > Java编译器 - >注释处理 - 出厂路径:增加上述所有罐子
Project -> Properties -> Java Compiler -> Annotation Processing - Factory path: Added all the above mentioned jars.
创建以下类:
public class Car {
private Engine engine;
@Inject
public Car(Engine engine) {
this.engine = engine;
}
public String carDetails(){
String engineName = this.engine.getName();
int engineNumber = this.engine.getNumber();
return "This car has the following details: \n" + engineName + "----" + engineNumber;
}
}
公共接口引擎{
public String getName();
public int getNumber();
}
public class Toyota implements Engine{
@Override
public String getName() {
return "This is toyota engine";
}
@Override
public int getNumber() {
return 1234567890;
}
}
@Component(modules = EngineModule.class)
public interface EngineComponent {
void inject();
}
@Module
public class EngineModule {
public EngineModule(DemoApplication demoApplication) {
}
@Provides
Engine provideEngine(){
return new Toyota();
}
}
但在 /公寓生成
文件夹有只有两个文件:
But inside /.apt-generated
folder there are only two files:
Car_Factory.java EngineModule_ProvideEngineFactory.java
DaggerEngineComponent.java
不是有我打造的组成部分。
DaggerEngineComponent.java
is not there for me to build the component.
可能有人请帮忙吗?
推荐答案
我猜注解处理器遇到错误和Eclipse没有显示你的日志。如果你登录的输出查看输出,您可能希望将其粘贴到这个问题。
I'm guessing the annotation processor is encountering an error and Eclipse is not showing you the log. If you have log output in the Output view, you may want to paste that into the question.
具体来说,我认为这是示数出来无效注射()
,这是不是在的。这些文档描述的方法分为两类:
Specifically, I think it's erroring out on void inject()
, which isn't a format descibed in the @Component
docs. Those docs describe two types of methods:
- 无参数的方法,返回一个类型的注射匕首创建并注入,如
引擎createEngine()
或 - 单参数的方法)
接收其它地方创建一个实例和应用方法和字段注入,如
无效injectEngine(发动机)
或引擎injectEngine(发动机
。- Parameterless methods that return an injectable type Dagger creates and injects, like
Engine createEngine()
, or - Single-parameter methods that receive an instance created elsewhere and apply method and field injection, like
void injectEngine(Engine)
orEngine injectEngine(Engine)
.
由于您的无效注射()
不匹配两种格式,匕首很可能示数并拒绝创建DaggerEngineComponent。
Because your void inject()
doesn't match either format, Dagger is likely erroring out and refusing to create a DaggerEngineComponent.
这篇关于匕首2:没有为组件接口生成的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!