Blog Archives

Android SDK on Ubuntu 10.04

It was about time to install Android SDK on my ASROCK workstation powered by Ubuntu 10.04. Right know, I’m using Dalvik Debug Monitor from Android SDK to take screenshot from my HTC Hero, but on the long run I think I’ll need the SDK if I’ll ever want to write and run some python script on Android using excellent SL4A (Scripting Layer for Android).

PART 1 – enabling ddms


Make sure Java jdk is in the path (if you don’t have java on your machine, install it with sudo apt-get openjdk-6-jdk).
I used JDK that I installed for Oracle SQLDeveloper.

$ export PATH=/oracle/jdk1.6.0_21/bin:$PATH
$ mkdir android_sdk
$ cd android_sdk
$ pwd
/home/alesk/android_sdk

Download and install Android SDK:

$ wget http://dl.google.com/android/android-sdk_r10-linux_x86.tgz
$ tar zxvf android-sdk_r10-linux_x86.tgz
$ cd android-sdk-linux_x86/

If you wish to run ddms (Dalvik Debug monitor) you’ll have to install “Android SDK Platform-tools”.
Launch android GUI and install package:

$ cd tools
$ ./android 

Open Available packages and select “Android SDK Platform-tools, Revision 3”:
AndroidSDKPlatformTools

After installation completes, make sure that you run adb as root (by default adb starts as user).

$ cd /home/alesk/android_sdk/android-sdk-linux_x86/platform-tools
$ ./adb kill-server
$ sudo ./adb start-server
[sudo] password for alesk: 
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

Check if you can see your phone as a device.

$ ./adb devices
List of devices attached 
HT97RL904617	device

Now you can start ddms (Dalvik Debug Monitor).

$ cd /home/alesk/android_sdk/android-sdk-linux_x86/tools
$ ./ddms

PART 2 – Preparing Android Emulator


$ cd android_sdk/tools
$ ./android

AndroidPrepareEmulator1
As you can see, there are no Virtual Devices yet. Let’s create one, but before we start we need to download and install API’s for target device.
Select “Installed packages”, then button “Update all”. From the list I selected Accept All. Be patient, it’ll take quite some time for download to finish (it took approx. 2 hours on 1Mbps “broadband”).

AndroidSDK-InstalledPackages

After downloads complete we can start creating Virtual Android device that’ll serve as emulator.
Click button “New”, then fill necessary information about your target device. Since I own HTC Hero with Android OS 2.1 I created virtual devices as shown on the picture:

AndroidPrepareEmulator2

After you click on “Create AVD”, you’ll see newly created virtual device among Virtual devices section.

AndroidPrepareEmulator3

Now, we can start Virtual device by selecting device from the list and clicking on Start button, then on Launch button (leaving everything on the menu in default state).

It can take several minutes for Virtual Device to “boot”, in short, don’t expect from emulator the same speed as if you’re using “real” phone (on my ASROCK, with dual core Atom processor, it took approx. five minutes to boot the virtual phone device. In general, everything is extremely slow compared with a real Android phone!). Eventually, you should see android home screen similar to this one:

AndroidPrepareEmulator4

Use mouse to unlock your “phone”, by dragging lock to the right. Mouse click replaces a “tap” on real phone.

AndroidPrepareEmulator5

I tested my newly created virtual “HTC Hero” device by installing Python for Android and SL4A according to this article..

AndroidPrepareEmulator6

If you “tap” on SL4A you should see python demo scripts.

AndroidPrepareEmulator7

Let’s say that we wrote some python script (hello_dbaportal.py) that we want to upload to virtual device, it’s as easy as:

$ cd android_sdk/platform-tools
$ ./adb push hello_dbaportal.py /sdcard/sl4a/scripts 
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
1 KB/s (80 bytes in 0.077s)

If you check emulator, you’ll find python script hello_dbaportal.py, from where you can run the code…

AndroidPrepareEmulator8

or, if you’re keen to fiddle with the script inside emulator, you can also edit the script…

AndroidPrepareEmulator9

Python for Android

I knew it was just a matter of time when someone ports python to Android. Kudos to Google employee Damon Kohler, who decided to built SL4A – Scripting Layer For Android in his 20% time that Google allows their employees to work on “pet projects”. Not only that SL4A supports python, other contributors ported some other popular interpreters to SL4A, such as Perl, JRuby, JavaScript, Lua, BeanShell and Tcl…more interpreters are on the way.
Linux Journal published interesting article in March issue, #204, titled “Python for Android”.
I’m happy to report that installing SL4A and python for Android on my HTC Hero (running Android 2.1) as described in the above article was trivial.

Here are the steps on how to install SL4A and Python for Android on HTC Hero (with OS 2.1):

  • Temporary enable installation of applications from unknown sources
    Menu -> Settings -> Applications -> check "Unknown sources"

    HTCUnknownSources

  • open Android web browser on your HTC phone and go to http://code.google.com/p/android-scripting/.
    If you tap on “QR Code” on the web page you’ll start downloading SL4A, at the time of this writing it was sl4a_r3.apk.
    After download completes, simply tap the downloaded apk package, then tap on Install button. This will install SL4A on your phone. Test the installation by tapping on Open button to open SL4A. If you receive warning “No matches found” simply ignore it, because you don’t have any script yet.
    Now, that we have SL4A “engine” ready, it’s time to install Python itself.
  • return to Android web browser and open the page http://code.google.com/p/android-scripting/. Find “Featured Downloads” section on left side of the page, then find the package PythonForAndroid_r4.apk. Tap the package to initiate the download, when download completes tap the package to start installation by tapping “Install button”.
    When installation completes tap the “Open button” followed by tap on Install button. This will download and install python support libraries from SL4A web site and add them to SL4A.
    HTC-Python
  • That’s it. If you check your Applications you’ll see two new icons, “Python for Android” and “SL4A”. At the time of this writing, python version was 2.6.2.
    HTCPythonForAndroid
  • If you open SL4A you should see some pre-created python demo scripts on the list.
    HTC-SL4A

  • If you tap on the particular script you can pick action from the menu.
    HTC-SL4A-menu

  • For example, you can Edit the script.
    HTC-SL4A-edit

  • Finally, don’t forget to disable option that allows installing applications from unknown sources (see point #1).