尝试在带有Lollipop的Nexus 7上使用espresso(即GoogleInstrumentationTestRunner
)运行与UI相关的代码测试会出现以下错误:
java.lang.IllegalStateException: This message cannot be recycled because it is still in use.
at android.os.Message.recycle(Message.java:279)
at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:468)
at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl.loopMainThreadUntilIdle(UiControllerImpl.java:337)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run(ViewInteraction.java:94)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这显然是known issue for several months,但由于已经有no commits since January 8,所以不知道是否会有正式修复。
讨论主题中有一条评论说明
删除message.recycle();似乎解决了......
这是一种有效的解决方法吗?如果没有,那么正确的解决方案是什么?
答案 0 :(得分:5)
更新:使用Espresso 2.0支持Lollipop https://code.google.com/p/android-test-kit/wiki/EspressoSetupInstructions
是的,如果您删除" message.recycle(); "并重建它将解决这个问题。
Espresso团队在GTAC宣布,Espresso的下一个版本将在很长一段时间内进入AOSP。观看视频:https://www.youtube.com/watch?v=aHcmsK9jfGU
(我是你引用的那个问题的原始海报)
更新:
// you will want to keep it for older API versions
if ( SDK_INT < 21 ){
message.recycle();
}