Can not change context on android emulator

appium version: 1.8.1
node version: 6.1.0
OS: Linux 4.15.0-24-generic x86_64
Virtualization: KVM (version 12) is installed and usable.
chromedriver depends on webview version

Emulator commands:

avdmanager create avd -n $AVD_NAME -k “system-images;android-%API_LEVEL%;google_apis;x86” -d “Nexus 9” --force

nohup $ANDROID_HOME/tools/emulator -avd $AVD_NAME -port $EMULATOR_PORT -use-system-libs -no-window -memory 1024 -no-boot-anim -partition-size 1024 -wipe-data -writable-system -noaudio -nocache -no-snapshot< /dev/null > /dev/null 2>&1 &

echo ‘vm.heapSize=256’ >> $CONFIG_FILE_PATH/config.ini

config.ini:

PlayStore.enabled=false
abi.type=x86
avd.ini.encoding=UTF-8
hw.accelerometer=yes
hw.audioInput=yes
hw.battery=yes
hw.cpu.arch=x86
hw.dPad=no
hw.device.hash2=MD5:939e2e20a04a4c645e5130616c6ff5b5
hw.device.manufacturer=Google
hw.device.name=Nexus 9
hw.gps=yes
hw.lcd.density=320
hw.lcd.height=1536
hw.lcd.width=2048
hw.mainKeys=no
hw.sdCard=yes
hw.sensors.orientation=yes
hw.sensors.proximity=no
hw.trackBall=no
image.sysdir.1=system-images/android-25/google_apis/x86/
tag.display=Google APIs
tag.id=google_apis
vm.heapSize=256

Appium logs:
appium_log.txt (712.1 KB)

Logcat:
logcat_emulator_log.txt (704.9 KB)

Looking at your Appium log, I think the version of Chromedriver you are using is not matched to the version of Chrome on your test device:

2018-07-18 07:08:51:146 - info: [debug] [Chromedriver] Changed state to ‘stopped’
2018-07-18 07:08:51:146 - error: [Chromedriver] Error: Failed to start Chromedriver session: An error occurred (Original error: chrome not reachable
2018-07-18 07:08:51:146 - error: [Chromedriver] (Driver info: chromedriver=2.28.455506 (18f6627e265f442aeec9b6661a49fe819aeeea1f),platapplication=Linux 4.15.0-24-generic x86_64))

“chrome not reachable” is the message I get when the versions are mismatched and chromedriver 2.28 is pretty old at this point so I would imagine that your device’s Chrome browser is updated but the driver is not… Fire up Chrome on your Android to see what version you have and the go here to get the appropriate chromedriver:

There is a folder for the updated chromedriver in Appium’s node_modules folder.

Good Luck!