Debugging mobile apps on linux

Mobile apps sometimes don’t work as expected, and you need to debug what the root cause is. Can you fit the whole required set of tools on one computer?

Can a single PC capture network traffic and syslog from an Android or iOS device at the same time?

The answer is yes.

My lab setup is running on Ubuntu Linux 16.04 LTS and is installed on a laptop. You could probably use any Linux distribution, but Ubuntu 16.04 has two handy features: it can very easily set up a wireless Hotspot. As you probably realized by now, this is how the network traffic capture is going to be done. The other reason I’m using Ubuntu is that it has tools for mobile devices in it’s repository – you don’t have to compile them by yourself.

You will also need an Internet connection, for example by using ethernet or USB cellular modem. If the app you’re debugging misbehaves when using a specific operator’s network, simply use that provider as your Internet connection.

First let’s set up the connection in Network Connections.

screenshot-from-2016-10-12-09-25-55Click “Add“. Name your connection, choose an SSID for your lab network and switch Mode to Hotspot.

screenshot-from-2016-10-12-09-26-28Next, go to IPv4 tab and set adressing Method to “Shared to other computers

screenshot-from-2016-10-12-09-27-02Click “Save“.

Now to start up your hotspot, simply click network manager icon and choose “Connect to Hidden WiFi Network”.

screenshot-from-2016-10-12-09-25-09From connection list, choose the connection you have just created.

Now we can capture network traffic by simply using tcpdump. In my case, wireless adapter is named wlan0.

sudo tcpdump -i wlan0 -s 1600 -w /tmp/capture.pcap

Now connect your mobile device to your Ubuntu Hotspot and we can begin testing our app.

What about device syslog?

Capturing network traffic is jut part of the solution. In most cases you will also need syslog from the mobile device, so you can correlate both logs. iOS and Android require different tools to capture syslog.

For iOS you can use a set of tools provided by libimobiledevice, which by the way can do all the stuff that iTunes on Windows can do. And even more.

First let’s install the required packages:

sudo apt-get install libimobiledevice6 libimobiledevice-utils

Now connect to your iOS device using USB cable and start this command to begin logging

idevicesyslog | tee /tmp/iossyslog

To access logs on an Android device, you will need logcat, which is part of android-tools-adb package

sudo apt install android-tools-adb

To begin capturing log from Android simply type

adb logcat | tee /tmp/androidsyslog

That’s it for today

This setup is battle-tested and already helped to debug network problems in one of the most popular mobile games for iOS and Android. You can easily extend it, for example by tuning (breaking) DNS or other network services, or by using a transparent HTTPS proxy to decrypt https traffic.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.