This article describes how to monitor network traffic running the Android AVD Emulator on Linux.
Android Studio And AVD Manager
The AVD emulator is part of Android Studio which is Google’s Android the development suite. Thus, it is a prerequisite to install it. You can install it into your home directory, e.g. into
After installation you will find two directories there:
android-studio which contains the IDE itself and
android-sdk-linux which contains all development and build tools.1
You should set up an environment variable
ANDROID_HOME which shall point to the sdk directory, e.g.
Once successfully installed, you can create virtual images. Use the AVD manager which is found either as the command line tool
avdmanager or within Android Studio: Tools -> Android -> AVDManager. It is suggested to create an x86-image because it performs much better since it is virtualized and not just emulated.
Create your virtual Android image with it. The images are stored in your home directory at
The AVD Emulator
The AVD emulator is actually based on qemu which is a great emulation and virtualization tool for Linux.
For network traffic we have to run the virtual image from the command line. First try and run the emulator from the command line to see if your image works.
$ANDROID_HOME/emulator/qemu/linux-x86_64/qemu-system-i386 -avd <NAME_OF_AVD>
The emulator shall start your virtual smartphone.
Problably you see the following error message:
Failed to open lib64EGL_translator: [lib64EGL_translator.so: cannot open shared object file: No such file or directory] gles2_dispatch_init: Could not load lib64GLES_V2_translator [lib64GLES_V2_translator.so: cannot open shared object file: No such file or directory] emulator: ERROR: Could not load OpenGLES emulation library [lib64OpenglRender]: lib64OpenglRender.so: cannot open shared object file: No such file or directory emulator: ERROR: Could not initialize OpenglES emulation, use '-gpu off' to disable it.
The reason is that the emulator cannot find the shared libraries which are shipped with it in the package.
Thus just add it to the
Run the emulator again, iit should work now.
Set Up A TAP Device
Now let’s setup a TAP device to which we will attach the virtual Android machine and Wireshark 😉
Run the following commands as root:
ip tuntap add name tap0 mode tap ip link set tap0 up ip address add 10.0.2.2/24 dev tap0 ip address add 10.0.2.3/24 dev tap0
Now we have to setup routing and NAT that the virtual machine is able to access the Internet (you can skip this if you don’t need Internet).
In my example
wlan0 is the outgoing network interface of the host computer (the Linux box) and 192.168.2.12 is the IP address of your DNS server (see
/etc/resolv.conf). You have to change these values appropriately!
sysctl net.ipv4.conf.all.forwarding=1 iptables -t nat -A POSTROUTING -s 10.0.2.0/24 -o wlan0 -j MASQUERADE iptables -t nat -A PREROUTING -d 10.0.2.3 -j DNAT --to-destination 192.168.2.12
Now run the emulator again and add the networking options to qemu as follows:
$ANDROID_HOME/emulator/qemu/linux-x86_64/qemu-system-i386 -avd <NAME_OF_AVD> -qemu -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no
Now you can attach Wireshark to the
tap0 device and monitor every packet 🙂
You could even attach
Have phun watching the dirty traffic of all those apps!
- In theory it is possible to develop Android apps just with the SDK and a good editor such as vi 😉 ↵