# @ your EC2 instance
sudo apt update
sudo apt install openjdk-8-jre unzip
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d android-sdk
sudo mv android-sdk /opt/
export ANDROID_SDK_ROOT=/opt/android-sdk
echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
echo "export PATH=$PATH:$ANDROID_SDK_ROOT/tools" >> ~/.bashrc
source ~/.bashrc
cd /opt/android-sdk/tools/bin
./sdkmanager --update
./sdkmanager --licenses
./sdkmanager "system-images;android-25;google_apis;armeabi-v7a" "emulator" "platform-tools"
touch ~ubuntu/.android/repositories.cfg
mkdir /opt/android-sdk/platforms
/opt/android-sdk/tools/bin/avdmanager -v create avd -f -n MyAVD -k "system-images;android-27;google_apis;armeabi-v7a" -p "/opt/android-sdk/avd"
# @ your EC2 instance
sudo apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal xfce4 vnc4server
vncserver
vncserver -geometry 1600x900
Now modify the first block in ~/.vnc/xstartup
:
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
See this article for more details on VNC setup
Setup local port forwarding to allow your VNC client to connect to the server:
# @ your local machine
ssh -L 5902:localhost:5902 emulator-aws
Now run this command inside the terminal on your VNC client:
# @ your VNC terminal
/opt/android-sdk/emulator/emulator -ports 5554,5555 -avd MyAVD -gpu swiftshader_indirect -show-kernel
Note: I added -skin 768x1280
to fix the resolution issue I was facing.
echo "hw.audioInput=no" >> /opt/android-sdk/avd/config.ini
echo "hw.audioOutput=no" >> /opt/android-sdk/avd/config.ini
echo "hw.cpu.ncore=2" >> /opt/android-sdk/avd/config.ini
echo "hw.camera.back=none" >> /opt/android-sdk/avd/config.ini
echo "hw.camera.front=none" >> /opt/android-sdk/avd/config.ini
echo "hw.gsmModem=no" >> /opt/android-sdk/avd/config.ini
echo "hw.gps=no" >> /opt/android-sdk/avd/config.ini
echo "hw.accelerometer=no" >> /opt/android-sdk/avd/config.ini
echo "hw.battery=no" >> /opt/android-sdk/avd/config.ini
echo "hw.trackBall=no" >> /opt/android-sdk/avd/config.ini
echo "hw.dPad=no" >> /opt/android-sdk/avd/config.ini
echo "hw.sensors.proximity=no" >> /opt/android-sdk/avd/config.ini
echo "hw.sensors.magnetic_field=no" >> /opt/android-sdk/avd/config.ini
echo "hw.sensors.orientation=no" >> /opt/android-sdk/avd/config.ini
echo "hw.sensors.temperature=no" >> /opt/android-sdk/avd/config.ini
echo "hw.ramSize=4096" >> /opt/android-sdk/avd/config.ini
- Fixing 100% CPU: Disabling the "Ok Google" Hotword detection (run this after the emulator has loaded):
./adb shell "su root pm disable com.google.android.googlequicksearchbox"
- We run ARM emulation on x86 instance.
- We must use ARM ABI, since x86 requires KVM and EC2 instance doesn't support HW virtualization.
- We must disable GUI (-no-window) and audio (-no-audio) when running the emulator.
- We must specify "-gpu swiftshader_indirect" when running the emulator to prevent a boot loop.
- First startup takes VERY LONG time. Use "-show-kernel" to see kernel messages and in secondary console window use "/opt/android-sdk/platform-tools/adb logcat" to see the system log while the emulator starts.
/opt/android-sdk/tools/bin/avdmanager create avd -n TestEmulator1 -k "system-images;android-27;google_apis;armeabi-v7a" -c 2000M --tag "google_apis" --device "Nexus 5X"
/opt/android-sdk/emulator/emulator -ports 5554,5555 -avd TestEmulator1 -gpu swiftshader_indirect -show-kernel -skin "1080x1920" -wipe-data