Friday, September 11, 2015

GPU-emulation for Android Emulator on a headless Linux

Eventually Google've released GPU emulation to public with new SDK 24.3.4

With GPU-EMULATION  it is possible to move your Android test farm to clouds like AWS without pay lots of money for instances with GPU.

Here is a how-to configure a headless GNU/Linux for Android with GPU emulation.

# install packages for android sdk
dpkg --add-architecture i386
apt-get update
apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386 lib32stdc++6 lib32z1 -y

# install Xorg (along with 32bit libs) for emulator to work with imaginary GPU
apt-get install xserver-xorg xserver-xorg-video-dummy x11-xserver-utils \
 x11vnc libgl1-mesa-dev libx11-6 libx11-dev libx11-6:i386 libx11-dev:i386 -y

# create config file /etc/X11/xorg.conf

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
EndSection

Section "InputDevice"
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    HorizSync       28.0 - 33.0
    VertRefresh     43.0 - 72.0
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "dummy"
    VendorName     "Dummy Corporation"
    Option "NoDDC" "true"
    Option "IgnoreEDID" "true"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "NoLogo" "True"
    Option         "UseDisplayDevice" "none"
    SubSection     "Display"
        Virtual     1024 768
        Depth       24
    EndSubSection
EndSection

# start Xorg
Xorg :0


# get fresh SDK
wget http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz
.....

# do not forget about environment variables
JAVA_HOME=...

ANDROID_HOME=/usr/local/android/android-sdk-linux

LD_LIBRARY_PATH=${ANDROID_HOME}/tools/lib/gles_mesa:${ANDROID_HOME}/tools/lib/:${LD_LIBRARY_PATH}

PATH=${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${PATH}

export JAVA_HOME ANDROID_HOME PATH LD_LIBRARY_PATH

# after creating android virtual device, add to config.ini :
hw.gpu.enabled=true
hw.gpu.mode=mesa


# start emulator
DISPLAY=:0 emulator -avd a442 -no-boot-anim -noaudio -no-jni -gpu mesa

# see in logs
emulator: Initializing hardware OpenGLES emulation support
emulator: OpenGL Vendor=[Google (VMware, Inc.)]
emulator: OpenGL Renderer=[Android Emulator OpenGL ES Translator (Gallium 0.4 on llvmpipe (LLVM 3.5, 256 bits))]
emulator: OpenGL Version=[OpenGL ES 2.0 (3.0 Mesa 10.4.2 (git-))]

Ansible Rocks

Even when you don't want to create playbooks http://docs.ansible.com/ansible/intro_adhoc.html

Real help with farms of virtual appliances in OpenStack or AWS