我无法用 dagger 编译我的项目,它在日志中显示以下错误:
Caused by: java.lang.IllegalStateException: Module adapter for class myproject.org.modules.ActivityModule could not be loaded. Please ensure that code generation was run for this module.
如果我注释掉对象图,我的项目就可以正常工作,这样我就知道它的设置是正确的。
这是我在 android 中扩展应用程序的 MainApplication 类:
public class MainApplication extends Application {
private ObjectGraph objectGraph;
@Override
public void onCreate() {
super.onCreate();
objectGraph = ObjectGraph.create(new ActivityModule());
objectGraph.inject(this);
}
}
这是我唯一的模块:
ActivityModule.java 类如下:
@Module(
injects=
ListPageActivity.class
)
public class ActivityModule { }
这是我的 gradle 构建依赖项:
dependencies {
compile files('libs/volley.jar')
apt "org.androidannotations:androidannotations:3.0+"
compile "org.androidannotations:androidannotations-api:3.0+"
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup:javawriter:2.5.1'
compile 'javax.inject:javax.inject:1'
compile fileTree(dir: 'libs', include: ['*.jar'])
这是我的项目 gradle 构建文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
出于某种原因,我认为这与 Dagger 无关,我的 IDE 中是否缺少包或配置?我已经搜索过 SO 并尝试包括 javawriter 以获取依赖项,但它没有解决这个问题。
最佳答案
你需要添加
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
到您的依赖项,以便代码生成将运行在您的类上。
关于android - Dagger 错误 - 模块上没有代码生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587066/