Are Android Animations Annoying You?

If this title doesn’t make sense. No worries. Come here when you start writing functional automation test and need to run it against Android Emulator.

The Problem (Skip this section, if all you need is solution)

Hence, all we wanted was to disable the animations on our emulator. So for solving the problem, I had very clean and clear approach (same as what most of the developers do):

I followed the above mentioned process. I went till the second page. Got some solutions. While automating the stuff, figured out sometimes it worked; other times it won’t. It felt like the emulator is playing games. Being infrastructure persons on the project, it was our job to make sure the emulator have animations disabled. We had to screen share into our build agents, open the emulator manually and verify the animations are disabled. That is just ridiculous in today’s world of automation. I decided to dedicate my weekend to this. Played a lot with the adb, avdmanager and emulator commands. Went into the kernel of the android emulator. With God’s grace, I finally got the fruit.(as they say — “Patience is bitter but its fruit is sweet”)

Finding

Solution

Note: In this snippet I am configuring avd(android virtual device) named “Nexus_25”. You can name your avd whatever you want. Just replace “Nexus_25” with your avd name, in the below code snippet.

#!/usr/bin/env bash
set -e

EMULATOR_PROCESS_ID_FILE_PATH=~/.Nexus_25.pid

function open_device()
{
$ANDROID_HOME/emulator/emulator -avd Nexus_25 -no-boot-anim -no-audio -no-window > /dev/null &

echo $! > $EMULATOR_PROCESS_ID_FILE_PATH #pid of previous command execution
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 10; done' #Wait until home screen gets displayed
}


function modify_settings()
{
$ANDROID_HOME/platform-tools/adb shell "settings put global window_animation_scale 0.0
"
$ANDROID_HOME/platform-tools/adb shell "settings put global transition_animation_scale 0.0"
$ANDROID_HOME/platform-tools/adb shell "settings put global animator_duration_scale 0.0"

#change whatever settings you wish to.
}

function restart_device()
{
$ANDROID_HOME/platform-tools/adb shell "su 0 am start -a android.intent.action.REBOOT"
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 10; done' #Wait until home screen gets displayed
}

function switch_off_device()
{
kill -9 $(cat $EMULATOR_PROCESS_ID_FILE_PATH)
#Why this? Because we don't trust adb emu kill
rm $EMULATOR_PROCESS_ID_FILE_PATH
}


open_device
modify_settings
restart_device
switch_off_device

P.S. This might not be the only solution. But it is a solution. Feedbacks are appreciated.

--

--

https://sagarmaurya.dev | BuyMeACoffee: https://www.buymeacoffee.com/sagarising

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store