我刚刚升级了我们的项目以使用Roboguice 3,突然间所有注入的对象都变为null,包括POJO,Providers,Views,Resources等.我正在努力弄清楚原因.
首先是gradle构建文件,试用Proguard开启和关闭它并没有什么区别.我相信我们目前正在使用Roboguice 3.0.1,但我尝试了3.0并仍然遇到了问题.
compile ('org.roboguice:roboguice:3.+') {
exclude module: 'asm'
}
provided 'org.roboguice:roboblender:3.+
Run Code Online (Sandbox Code Playgroud)
我们在模块文件中有一些自定义绑定,所以这是我如何根据wiki指定它:
<meta-data
android:name="roboguice.modules"
android:value="com.some.CustomModule"/>
Run Code Online (Sandbox Code Playgroud)
只是为了记录我还尝试在这样的Application类中指定它并且它不起作用:
RoboGuice.getOrCreateBaseApplicationInjector(
this,
RoboGuice.DEFAULT_STAGE,
RoboGuice.newDefaultRoboModule(this),
new CustomModule(this));
Run Code Online (Sandbox Code Playgroud)
这是关于它的设置,我们没有改变任何东西,如果我使用Roboguice 2,一切正常.
我还尝试了其他一些事情:
RoboGuice.setUseAnnotationDatabases(false);它没有什么区别.Ln.d("Test" + Strings.toString(0)); 这个日志打印得很好所以我认为实际的库是正确打包的.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注释的公共构造函数,我想不知何故它没有被考虑在内?也许整个问题是由于没有考虑注释?我已经对它进行了几天的撞击,并且非常感谢任何输入或更多的东西尝试.