25

I turned off all animations on developer options. But I still get this exception when trying to click on one of the buttons.

My app is indeed active and not idle entirely, but I can't change it.

android.support.test.espresso.AppNotIdleException: Looped for 6930
iterations over 60 SECONDS. The following Idle Conditions failed .
 at dalvik.system.VMStack.getThreadStackTrace(Native Method)
 at java.lang.Thread.getStackTrace(Thread.java:580)
 at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:92)
 at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
 at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
 at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
 at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
Zoe
  • 27,060
  • 21
  • 118
  • 148
user5174803
  • 261
  • 1
  • 3
  • 5
  • Possible duplicate of [Espresso freezing on view with looping animation](http://stackoverflow.com/questions/29550508/espresso-freezing-on-view-with-looping-animation) – piotrek1543 Aug 10 '16 at 00:00
  • What do you mean by "app is active"? Are you doing some background thread operations or is this a progress indicator? Do you have a custom IdlingResource which returns an empty string in getName()? – Be_Negative Sep 18 '16 at 19:36
  • 1
    http://stackoverflow.com/a/40240310/3902106 you can refer to my answer on another thread. – Apurva Sharma Oct 25 '16 at 12:55
  • You can also refer to my answer at http://stackoverflow.com/questions/38797738/espresso-appnotidleexception/40240310#40240310 – Apurva Sharma Oct 25 '16 at 13:21
  • See my answer to a very similar question (AppNotIdleException was thrown sometimes): https://stackoverflow.com/questions/35460708/espresso-onview-inconsistent-performance/44920191#44920191 – Eirik W Jul 05 '17 at 13:19

4 Answers4

5

I have been struggling with this problem for the last few days.
Here is a method that I used to identify "violators":

private void dumpThreads() {
    int activeCount = Thread.activeCount();
    Thread[] threads = new Thread[activeCount];
    Thread.enumerate(threads);
    for (Thread thread : threads) {
        System.err.println(thread.getName() + ": " + thread.getState());
        for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
            System.err.println("\t" + stackTraceElement);
        }
    }
}

In my case, Facebook SDK was using the AsyncTask thread pool.

deadmoto
  • 482
  • 5
  • 8
  • 2
    You can also pause the app (in debug mode) when it hangs and look at all the AsyncTasks that are in the 'RUNNING' state. – Rich Ehmer Jun 06 '17 at 20:58
  • How did you deal with this issue? I have a similar problem that I believe is the FacebookInitProvider making a call that stalls and causes the exception but have been unable to find away to avoid the call being made. – Gapp Jun 27 '19 at 08:21
2

In my case this problem was happening with AnimatedVectorDrawable and caused by an objectAnimator that was set to repeat the animation infinitely (android:repeatCount="infinite"). .

The problem was also present only on older platform versions. Tests were perfectly working on Android 9 while the problem was reproducible on Android 5 and 6 (not sure about 7 and 8 at the moment).

I believe, the root cause of the problem is the same as for indeterminate progress bars (covered in this SO question). However, I haven't found any nice solution, only workarounds.

One of the workarounds is to detect that the animation is turned off (animator duration is 0) in the setting and don't start the animation. Of course, this only works for platform versions where the animation does not autostart.

private fun startIconAnimation(imageView: ImageView) {
    if (areAnimationsEnabled()) {
        (imageView.drawable as Animatable).start()
    }
}

private fun areAnimationsEnabled(): Boolean {
    val animatorDurationScale = Settings.Global.getFloat(
        requireContext().contentResolver,
        Settings.Global.ANIMATOR_DURATION_SCALE,
        1.0f
    )
    return animatorDurationScale != 0.0f
}

Note: API level 26 introduced a static method ValueAnimator.areAnimatorsEnabled() which would have been handy if the problem was not happening only on the older platform versions.

Josef Adamcik
  • 5,620
  • 3
  • 36
  • 42
1

As per answer by MaciejGórski to the similar question:

It was a bug in my app code, where SwipeRefreshLayout animated itself indefinitely. Due to a bug in this component, the refresh state was not even showing.

Community
  • 1
  • 1
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
0

In my case I clicked "save" button running long request in a test. To complete the test I had to add idle() after save() method. But often it was not enough, a loader continued drawing and the test failed. Then I increased a duration: idle(10000) and got the error: androidx.test.espresso.AppNotIdleException: Looped for 238 iterations over 10 SECONDS. The following Idle Conditions failed DELAY_HAS_PAST..

I wrote: idle(5000). Instead of Espresso I use Kakao and Kaspresso.

CoolMind
  • 26,736
  • 15
  • 188
  • 224