Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a workaround for using espresso with Lollipop (Android 21)?

Attempting to run a test with UI-related code using espresso (i.e. GoogleInstrumentationTestRunner) on a Nexus 7 with Lollipop gives the following error:

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)

This has apparently been a known issue for several months but since there have been no commits since January 8, it is unknown whether there will be an official fix.

There is a comment in the discussion thread that states

Just removing message.recycle(); seems to fix it...

Is this a valid workaround? If not, what would the correct fix be?

like image 967
Jedidja Avatar asked Nov 24 '14 17:11

Jedidja


1 Answers

UPDATE: Use Espresso 2.0 for Lollipop support https://code.google.com/p/android-test-kit/wiki/EspressoSetupInstructions

Yes, if you remove "message.recycle(); " and rebuild it will solve that problem.

The Espresso team announced at GTAC that the next release of Espresso will be in AOSP before too long. See video here: https://www.youtube.com/watch?v=aHcmsK9jfGU

( I was the original poster of that issue you referenced )

UPDATE:

// you will want to keep it for older API versions
if ( SDK_INT < 21 ){
    message.recycle();
}

like image 79
yogurtearl Avatar answered Sep 28 '22 07:09

yogurtearl