升级到 Android Gradle 2.2.0 插件后,使用 Dagger 2 进行 Espresso 测试中的 ClassCastException
ClassCastException in Espresso test with Dagger 2 after upgrading to Android Gradle 2.2.0 plugin
自更新到 Android 2.2.0 Gradle 插件后,我的 Espresso 测试开始失败并出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app.debug/com.myapp.app.conversation.ConversationActivity}: java.lang.ClassCastException: com.myapp.app.conversation.data.SqlMessageStore cannot be cast to com.myapp.app.auth.UserScopedAccountStore
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access0(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassCastException: com.myapp.app.conversation.data.SqlMessageStore cannot be cast to com.myapp.app.auth.UserScopedAccountStore
at com.myapp.app.di.module.UserModule_UserScopedAccountStoreFactory.get(UserModule_UserScopedAccountStoreFactory.java:30)
at com.myapp.app.di.module.UserModule_UserScopedAccountStoreFactory.get(UserModule_UserScopedAccountStoreFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_TokenInterceptorFactory.get(UserModule_TokenInterceptorFactory.java:30)
at com.myapp.app.di.module.UserModule_TokenInterceptorFactory.get(UserModule_TokenInterceptorFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_AuthedOkHttpClientFactory.get(UserModule_AuthedOkHttpClientFactory.java:30)
at com.myapp.app.di.module.UserModule_AuthedOkHttpClientFactory.get(UserModule_AuthedOkHttpClientFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_HipChatClientFactory.get(UserModule_HipChatClientFactory.java:81)
at com.myapp.app.di.module.UserModule_HipChatClientFactory.get(UserModule_HipChatClientFactory.java:17)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_LogoutFactory.get(UserModule_LogoutFactory.java:29)
at com.myapp.app.di.module.UserModule_LogoutFactory.get(UserModule_LogoutFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_SignedInPresenterFactory.get(UserModule_SignedInPresenterFactory.java:69)
at com.myapp.app.di.module.UserModule_SignedInPresenterFactory.get(UserModule_SignedInPresenterFactory.java:16)
at com.myapp.app.BaseSignedInActivity_MembersInjector.injectPresenter(BaseSignedInActivity_MembersInjector.java:44)
at com.myapp.app.conversation.ConversationActivity_MembersInjector.injectMembers(ConversationActivity_MembersInjector.java:40)
at com.myapp.app.conversation.ConversationActivity_MembersInjector.injectMembers(ConversationActivity_MembersInjector.java:9)
at com.myapp.app.di.DaggerUserComponent.inject(DaggerUserComponent.java:993)
at com.myapp.app.conversation.ConversationActivity.inject(ConversationActivity.java:149)
at com.myapp.app.BaseSignedInActivity.onCreate(BaseSignedInActivity.java:59)
at com.myapp.app.conversation.ConversationActivity.onCreate(ConversationActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:532)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
... 10 more
运行 该应用程序运行良好。将其改回 Android 2.1.3 Gradle 插件修复了浓缩咖啡问题(没有其他更改)。我已尝试清理、重建和重新启动 gradle 守护程序,但均无济于事。我还尝试更新到 2.2.1 并升级到最新的 Dagger 2 版本 (2.7)。
您是否有重复的依赖关系?尝试使用 compileOnly
而不是 compile
来测试依赖项。
自更新到 Android 2.2.0 Gradle 插件后,我的 Espresso 测试开始失败并出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app.debug/com.myapp.app.conversation.ConversationActivity}: java.lang.ClassCastException: com.myapp.app.conversation.data.SqlMessageStore cannot be cast to com.myapp.app.auth.UserScopedAccountStore
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access0(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassCastException: com.myapp.app.conversation.data.SqlMessageStore cannot be cast to com.myapp.app.auth.UserScopedAccountStore
at com.myapp.app.di.module.UserModule_UserScopedAccountStoreFactory.get(UserModule_UserScopedAccountStoreFactory.java:30)
at com.myapp.app.di.module.UserModule_UserScopedAccountStoreFactory.get(UserModule_UserScopedAccountStoreFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_TokenInterceptorFactory.get(UserModule_TokenInterceptorFactory.java:30)
at com.myapp.app.di.module.UserModule_TokenInterceptorFactory.get(UserModule_TokenInterceptorFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_AuthedOkHttpClientFactory.get(UserModule_AuthedOkHttpClientFactory.java:30)
at com.myapp.app.di.module.UserModule_AuthedOkHttpClientFactory.get(UserModule_AuthedOkHttpClientFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_HipChatClientFactory.get(UserModule_HipChatClientFactory.java:81)
at com.myapp.app.di.module.UserModule_HipChatClientFactory.get(UserModule_HipChatClientFactory.java:17)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_LogoutFactory.get(UserModule_LogoutFactory.java:29)
at com.myapp.app.di.module.UserModule_LogoutFactory.get(UserModule_LogoutFactory.java:10)
at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
at com.myapp.app.di.module.UserModule_SignedInPresenterFactory.get(UserModule_SignedInPresenterFactory.java:69)
at com.myapp.app.di.module.UserModule_SignedInPresenterFactory.get(UserModule_SignedInPresenterFactory.java:16)
at com.myapp.app.BaseSignedInActivity_MembersInjector.injectPresenter(BaseSignedInActivity_MembersInjector.java:44)
at com.myapp.app.conversation.ConversationActivity_MembersInjector.injectMembers(ConversationActivity_MembersInjector.java:40)
at com.myapp.app.conversation.ConversationActivity_MembersInjector.injectMembers(ConversationActivity_MembersInjector.java:9)
at com.myapp.app.di.DaggerUserComponent.inject(DaggerUserComponent.java:993)
at com.myapp.app.conversation.ConversationActivity.inject(ConversationActivity.java:149)
at com.myapp.app.BaseSignedInActivity.onCreate(BaseSignedInActivity.java:59)
at com.myapp.app.conversation.ConversationActivity.onCreate(ConversationActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.support.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:532)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
... 10 more
运行 该应用程序运行良好。将其改回 Android 2.1.3 Gradle 插件修复了浓缩咖啡问题(没有其他更改)。我已尝试清理、重建和重新启动 gradle 守护程序,但均无济于事。我还尝试更新到 2.2.1 并升级到最新的 Dagger 2 版本 (2.7)。
您是否有重复的依赖关系?尝试使用 compileOnly
而不是 compile
来测试依赖项。