这在特定的API 14和19中并不总是可见.
下面是堆栈跟踪
java.lang.NoClassDefFoundError: roboguice.inject.ContextScopedRoboInjector
at roboguice.RoboGuice.getInjector(RoboGuice.java:197)
at roboguice.activity.RoboActivity.onCreate(RoboActivity.java:90)
at com.bnmcombines.galleryflavors.Launcher.onCreate(Launcher.java:71)
at android.app.Activity.performCreate(Activity.java:5343)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
RoboGuice 3.0已经记录了一个问题:https://github.com/roboguice/roboguice/issues/328
但没有回应,我们目前被阻止.
这次我更仔细地提到了MultiDex Document,并将我更新AndroidManifest.xml到了我错过的下面
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud) 我刚刚升级了我们的项目以使用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注释的公共构造函数,我想不知何故它没有被考虑在内?也许整个问题是由于没有考虑注释?我已经对它进行了几天的撞击,并且非常感谢任何输入或更多的东西尝试.