我的测试在API级别为20及以上的设备上运行良好,但在API级别19及以下版本中失败。 问题似乎与roboguice有关,但我无法找到解决方案。 请帮忙。 日志如下。
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: FATAL EXCEPTION: main
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: Process: com.rr.rruniversal.mobile, PID: 1748
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: java.lang.NoClassDefFoundError: roboguice.inject.AssetManagerProvider
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:155)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.AbstractModule.configure(AbstractModule.java:78)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:252)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.spi.Elements.getElements(Elements.java:107)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.util.Modules$OverrideModule.configure(Modules.java:174)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.AbstractModule.configure(AbstractModule.java:78)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:252)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.spi.Elements.getElements(Elements.java:107)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:135)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.Guice.createInjector(Guice.java:100)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.google.inject.Guice.createInjector(Guice.java:87)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at roboguice.RoboGuice.createGuiceInjector(RoboGuice.java:186)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at roboguice.RoboGuice.getOrCreateBaseApplicationInjector(RoboGuice.java:114)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at net.doo.snap.ScanbotSDKInitializer.initialize(SourceFile:119)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.rruniversal.mobilelib.imagecapture.ImageCaptureInitializer.initialize(Unknown Source)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.hello.appuniversal.RRUniversalApp.onCreate(RRUniversalApp.java:126)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:325)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:135)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5001)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
03-15 05:06:54.600 1748-1748/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
03-15 05:06:54.600 532-707/? W/ActivityManager: Error in app com.rruniversal.app.mobile running instrumentation ComponentInfo{com.rr.rruniversal.test/android.support.test.runner.AndroidJUnitRunner}:
03-15 05:06:54.600 532-707/? W/ActivityManager: java.lang.NoClassDefFoundError
03-15 05:06:54.600 532-707/? W/ActivityManager: java.lang.NoClassDefFoundError: roboguice.inject.AssetManagerProvider
我哪里错了?有什么特别需要在build.gradle中作为依赖项包含吗? 我添加的依赖项如下:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs', 'module': 'jsr305'
}
// Espresso-web for WebView support
androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.1') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs', 'module': 'jsr305'
}
由于我在同步时遇到冲突,因此排除了。我在我的应用程序中使用SDK Level 23。 任何帮助都可以。提前谢谢!
答案 0 :(得分:0)
我和你有同样的问题,最后让它在KitKat上工作......这是我目前的工作配置:
Butterknife等。
Android Gradle Plugin 2.1.0
对于特定于依赖关系的Android测试,我有:
androidTestCompile ("com.android.support.test:runner:$runnerVersion") androidTestCompile ("com.android.support.test:rules:$rulesVersion") androidTestCompile ("com.android.support:support-annotations:$androidSupportLibraryVersion") androidTestCompile ("com.android.support.test.espresso:espresso-core:$espressoVersion") { exclude group: 'javax.inject' } androidTestCompile ("com.android.support.test.espresso:espresso-intents:$espressoVersion") { exclude group: 'com.android.support.test.espresso', module: 'espresso-core' } androidTestCompile ("org.mockito:mockito-core:$mockitoVersion") { force = true } androidTestCompile ("com.crittercism.dexmaker:dexmaker:$dexmakerVersion") androidTestCompile ("com.crittercism.dexmaker:dexmaker-dx:$dexmakerVersion") androidTestCompile ("com.crittercism.dexmaker:dexmaker-mockito:$dexmakerVersion")
,其中
mockitoVersion = "1.10.19" runnerVersion = "0.5" rulesVersion = "0.5" espressoVersion = "2.2.2" dexmakerVersion = "1.4"
在您的情况下,您可能想要添加:
androidTestCompile ("com.android.support.test.espresso:espresso-web:$espressoVersion") { exclude group: 'com.android.support.test.espresso', module: 'espresso-core' }
如果你没有使用mockito,那么我想你可以跳过dexmaker依赖 - 他们只需要让mockito工作(至少在我的项目中)。
希望这能解决你的问题!