Wednesday, September 16, 2009

How to install android sdk 1.6 on Ubuntu 9.04


Google has recently released version android SDK 1.6. This tutorial will teach you how to install it on ubuntu 9.04.

1 Installing Java
Android SDK is built around Java . So, you have to install Sun Java before trying to install Android. Look at this post for details about installation of sun java development kit on ubuntu 9.04.

2) Download android sdk. The current version ( 1.6 R1 ) is available as a tar.gz file from google. Look at this link . You will be prompted to accept android licence and if you accept it, you will be redirected to another link which will permit you to download the sdk. ( It is around 222MB)

3) Unzip the tar.gz file .
I unzipped it to my home folder with the following command

$ tar -xzvf android-sdk-linux_x86-1.6_r1.tgz

All the files were unzipped to a folder named android-sdk-linux_x86-1.6_r1
If you look at the directory now , you will see the following files and folders.

$ ls android-sdk-linux_x86-1.6_r1

add-ons docs documentation.html platforms RELEASE_NOTES.html tools

The tools for android development is under the tools directory.

4) Test drive the android emulator

Since all the android tools are kept under android-sdk-linux_x86-1.6_r1/tools, we must modify the PATH environment variable so that it includes the above directory too.Open a terminal and execute the following.
fermi @Jaunty:~$ PATH=${PATH}:~/android-sdk-linux_x86-1.6_r1/tools
fermi @Jaunty:~$ export PATH
You can also add the above line to your ~/.bash_profile or ~/.bashrc , so that the setting is available always.

My PATH variable looks like this after the above command.

fermi @Jaunty:~$ echo $PATH
/home/fermi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/fermi/android-sdk-linux_x86-1.6_r1/tools

Now you can test fire your set up . It is a good idea to keep all your android related files in a separate folder. I created a new folder named ANDR for experimenting. All the commands below are executed in that folder.

The virtual phones created by android SDK are called AVDs ( android virtual device) .Let us start the experiment with a virtual SDcard and a Virtual Phone.

Let us create a virtual SDcard

$ mksdcard 2048M SDCARD
If you look at the contents of the folder you will see a 2GB file named SDCARD

Next, create an android virtual phone named FERMI_PHONE.

$ android create avd -n FERMI_PHONE -t 2
Android 1.6 is a basic Android platform.
Do you wish to create a custom hardware profile [no]

Press enter to choose no. You will get back the following message.

Created AVD 'FERMI_PHONE' based on Android 1.6, with the following hardware config:
hw.lcd.density=160

Now start up android emulator.
$ emulator @FERMI_PHONE -sdcard SDCARD

Your virtual phone pops up as below. ( Another window which asks you to participate in a survey also pops up, you can close it.)




Wait for a moment , your screen will change to the one shown below.



You can press menu button to unlock the phone.



You can flip the phone with CNTRL+F11



Now let us browse on the android phone.


5 )Starting development with SDK.

The easiest way to start development on android is via eclipse. The eclipse version shipped with jaunty is some what old. ( Version: 3.2.2-5ubuntu3) . You need a later version for installing the ADT ( android Development tools ) for eclipse. I downloaded Eclipse 3.5 (Galileo) from the eclipse site and installed it . Then completed the following steps.
  1. Start Eclipse, then select Help > Install New Softare.
  2. In the Available Software dialog, click Add....
  3. In the Add Site dialog that appears, enter a name for the remote site (e.g., "Android Plugin") in the "Name" field.

    In the "Location" field, enter this URL:

    https://dl-ssl.google.com/android/eclipse/

    Click OK.

  4. Back in the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools. Click Next.
  5. In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish.
  6. Restart Eclipse.
Now modify your Eclipse preferences to point to the Android SDK directory:

  1. Select Window > Preferences... to open the Preferences panel
  2. Select Android from the left panel.
  3. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.
  4. Click Apply, then OK.
Now your development environment is ready.

For running a hello world application, read this entry from the developers guide. Here is a screen shot of my hello world application.


Happy Hacking.

13 comments:

Anonymous said...

Hello and thanks for a nice guide.

There is couple of things to do before you can feed the application to a real phone.

Check step 10) of this guide.
http://www.futuredesktop.org/developing_android_apps_on_ubuntu.html

It will tell you all.

Anonymous said...

Hello!
I got
mksdcard 2048M SDCARD
could not write to 'SDCARD', aborting...

What is wrong?

Fermi Level said...

Do you have permisson on in the folder you are trying to create Sd card

Fermi Level said...

See this
$ mksdcard 2048M /SDCARD
could not create file '/SDCARD', aborting...
Segmentation fault
This is because I don't have permission to create SDCARD in /

Anonymous said...

Hey, that was fun. Thanks for the guide. Now all I need is a real Android phone!

ശബ്ദശക്തി വ്യാഖ്യാകാരഃ said...

Simple
Easy to learn
I did it with 5 minutes.

Anonymous said...

from ubuntu 6.06 on ~/.bash_profile does not work while xserver is running you must use ~/.bashrc

Unknown said...

I'm a big noob with linux, but how would I then remove the sdcard once I'm finished?

Eric Johansson said...

Try:

$ mksdcard [size in mb]M [sd card name][(path/)filename].bin

eg.

$ mksdcard 2048M SDCARD SDCARD.bin

MB34 said...

I can't run the Android install in Eclipse. The Next button will not enable.
I tired it before I actually got the adroid SDK installed and it didn't work because it wasn't installed. Now I can't install the Tools because the Next button won't enable.

Using Ubuntu 9.10, Eclipse 3.5.1 in VirtualBox on WinXP. Also can't find .bash files to add the path.

If someone can help me, please write mrbaseball34@gmail.com

Steve Withers said...

I upgrade a working Android 2.0 SDK environment to Ubuntu 9.10 last night. All went well except for two things:

1. There is a bug in Ubuntu that see your mouse unable to click on things at times. I noticed it most in Google Chrome.

2. ddms in \tools can't fully see my real android phone anymore. Instead of the phone's ID "H-whatever"....I get "???????".

I'm assuming the second problem may be permissions as Ubuntu also asked me for permissions to mount my 2nd data drive...which is always mounted by default. Once done, it was done.

But if others see this "????" issue with seeing the real phone, I wanted to make a note here. I've blogged about it, too.

Sd Cards said...

Hi,
This post is very useful and very interesting to read, really this Post is nice information, Keep it up.

Anonymous said...

I had the problem of being unable to install the Android plugin into eclipse. Whenever I clicked on "Next" it would give a mouse down look, but it wouldn't work. I ended up using the keyboard shortcuts - "Alt - N" and it worked fine.