Wednesday 19 October 2011

adb - getting inside your Android simulator

I've been working with persistent state between launches of my Android application and wanted to easily inspect my application data between launches. I discovered the power of the Android Debug Bridge or adb tool. In short a dev tool that lets you hook up against a running Android simulator.

You'll find it in your sdk folder under platform-tools. On my machine:
C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe

A few handy commands:

- List currently running devices:
>adb devices
List of devices attached
emulator-5554   device

- Launch a terminal shell against a running device
>adb -s emulator-5554 shell

Then you can do your ordinary linux stuff like cd, ls, cat etcetera to get to know your Android device.
My happiest discovery was that the preference file you fetch and save via the SharedPreference API:
SharedPreferences settings = getSharedPreferences("OthelloLegendsPrefs", 0);

are located under the path
/data/data/se.noren.android.othello/shared_prefs/OthelloLegendsPrefs.xml

and is a simple XML file which you can inspect and edit.

So, to pull a file from the simulator to your development computer
>adb -s emulator-5554 pull <remotefile> <localfile>

Similarly, to upload a file to the device
>adb -s emulator-5554 push <localfile> <remotefile>

For more info on adb, http://developer.android.com/guide/developing/tools/adb.html.

3 comments: