【发布时间】:2014-12-08 21:43:33
【问题描述】:
我刚刚升级了我们的项目以使用 Roboguice 3,突然所有注入的对象都变为空,包括 POJO、提供程序、视图、资源等。我正在努力找出原因。
首先是 gradle 构建文件,尝试了开启和关闭 Proguard,但没有任何区别。我相信我们目前使用的是 Roboguice 3.0.1,但我尝试了 3.0 仍然有问题。
compile ('org.roboguice:roboguice:3.+') {
exclude module: 'asm'
}
provided 'org.roboguice:roboblender:3.+
我们在模块文件中确实有一些自定义绑定,所以这是我根据 wiki 指定它的方式:
<meta-data
android:name="roboguice.modules"
android:value="com.some.CustomModule"/>
为了记录,我也尝试在 Application 类中像这样指定它,但它不起作用:
RoboGuice.getOrCreateBaseApplicationInjector(
this,
RoboGuice.DEFAULT_STAGE,
RoboGuice.newDefaultRoboModule(this),
new CustomModule(this));
设置就是这样,我们没有改变任何东西,如果我使用 Roboguice 2,一切正常。
我也尝试过的其他几件事:
- 也尝试不使用 Roboblender 和注释 db
RoboGuice.setUseAnnotationDatabases(false);,但没有任何区别。 -
Ln.d("Test" + Strings.toString(0));这个日志打印得很好,所以我认为实际的库是正确打包的。 - 我没有注入 POJO 的 Provider,而是尝试使用像
RoboGuice.getInjector(this).getInstance(SharedPreferencesHelper.class);这样的手动注入,它会抛出有关Could not find a suitable constructor in some.path.SharedPreferencesHelper. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.的错误 奇怪的是,在 SharedPreferencesHelper 类中,我们确实有一个带有@Inject的公共构造函数注释,我想不知何故没有考虑到它?也许这整个问题是由于没有考虑注释?
我已经为此苦苦挣扎了几天,非常感谢任何意见或更多尝试的东西。
【问题讨论】:
标签: java android dependency-injection roboguice