Contents[Hide]

The purpose of this article is to get a reader started with an Android application development using an open source Android SDK on a Linux system. The main focus of the following lines will be concentrated on installation of Java based Eclipse IDE, Android SDK and Android Developer Tool (ADT) a special Eclipse plug-in on Ubuntu and Fedora Linux systems. The installation instructions will be followed by a simple Hello Android program example to test an entire installation.

Since the combination of Eclipse and Android SDK provides a powerful Android Virtual Device emulator, a reader does not need to own any Android device to get started with the Android application development.

1. Introduction

android logoAndroid is a mobile operating system initially developed by Android Inc and in year 2005 it was acquired by Google Inc. In year 2007 The Open Handset Alliance was formed, which includes Google and other 33 companies. The aim of The Open Handset Alliance is to bring innovation into mobile devices and thus giving consumers a much better user experience.

At the same time, mobile application developers are given an opportunity to freely participate in Android application development using alliance's Android Software Development Kit ( SDK ) which is released through Google's developer website. Developers are therefore, free to develop any Android application they see fit and are free to market it to all Android mobile phone owners. This article will consist of four main sections:

  • Installation of Eclipse IDE, Oracle Java JRE, Android SDK and Android Developer Tool (ADT) a special Eclipse plug-in
  • Setting up Eclipse IDE with Android SDK and Android Developer Tool
  • Writing a simple Android Application: "Hello Android"
  • Testing Android application using Android Virtual Device

2. Prerequisites

For this article, I used Ubuntu 10.04 Lucid Lynx LTS ( Long-term support ) and Fedora 14. However, all instructions below should work for any other recent Linux distribution. Therefore, requirements are very simple:

  • Working Linux System
  • Internet Connection

3. Installation

The only major difference in the whole installation procedure of Android Development environment between Ubuntu and Fedora is in installation of Eclipse ( rpm vs deb ) and Oracle Java JRE.

3.1. Eclipse IDE installation

Let us start with installation of Eclipse IDE.

3.1.1. Ubuntu

$ sudo apt-get install eclipse

3.1.2. Fedora

# yum install eclipse

3.2. Installation of Java SE Runtime Environment

In the next step, we will install the Oracle Java SE Runtime Environment. Both Linux systems Ubuntu and Fedora come with a default OpenJDK java environment. Commands below will install Oracle Java SE Runtime Environment and replace OpenJDK with Oracle JRE as a default java environment.

3.2.1. Ubuntu

Ubuntu had moved a Sun Java Runtime Environment 6 package away from a multiverse repository into proprietary repository "partner". Therefore, if you have not done so yet you need to add partner repository to your apt sources list first. The command below might vary depends what version of Ubuntu you are running. For Ubuntu 10.04 "Lucid" enter:

NOTE: If you are running Ubuntu maverisk replace lucid with maverick in the command below !

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update 

After the update simply use apt-get to install Sun Java JRE 6

$ sudo apt-get install sun-java6-jre galternatives

As a last step we need to change a default system's java environment from OpenJDK to Sun JRE 6. To do that enter a command:

$ sudo galternatives

Select java from left menu and select java-6-sun radio button. Once done, simply close galternatives window.

Default java ubuntu environment

Now verify the java installation with:

$ java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

3.2.2. Fedora

Same as Ubuntu also Fedora Linux system comes with a default OpenJDK Java fetched from a standard Fedora repository. This time however, we install Sun's Java JRE from source. First download a Sun JRE package:

Download URL:

http://www.oracle.com/technetwork/java/javase/downloads/index.html Next become a root:

$ su -

make the downloaded binary executable and execute:

NOTE: Depending on your current java version commands below may need to be modified.

# chmod +x jre-6u23-linux-i586.bin
# ./jre-6u23-linux-i586.bin 

At this point you should have a new jre1.6.0_23 in your current working directory. Move this directory to /opt/

# mv jre1.6.0_23/ /opt/ 

And swap OpenJDK with Sun Java JRE as a default java environment with:

# alternatives --install /usr/bin/java java /opt/jre1.6.0_23/bin/java 20000 

Now verify the java installation with:

$ java -version
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode)

3.3. Installation of Android Developer Tool (ADT)

Android Developer Tool is a special Eclipse plug-in which contains integrated android environment for building Android application using Eclipse. The following Android Developer Tool installation steps are same for both Fedora and Ubuntu. There might be small differences between dialog boxes, but the procedure is exactly the same.

IMPORTANT :

If you are running UBUNTU 10.10 Maverick please read an appendix ( Section 8.1 ) located at the end of this document before continuing !

Start eclipse and take a note of the eclipse version number by navigating to:

Help -> About Eclipse SDK

Follow steps below to install Android Developer Tool Eclipse plug-in for a Eclipse version <= 3.5.

Navigate to:

Help -> Install New Software -> Add

Insert a following information into the dialog box:

  • Name: ADT Plugin
  • Location: https://dl-ssl.google.com/android/eclipse/ OR http://dl-ssl.google.com/android/eclipse/

Add ADT plugin

Click OK and tick "Developer Tools". Developer tools installation option should appear once Eclipse syncs with a new installation URL added earlier.

Android Eclipse Plugin

Watch for an Error:


If you get an error message saying:

Cannot complete the install because one or more required items could not be found.
Software being installed: Android Development Tools 8.0.1.v201012062107-82219
(com.android.ide.eclipse.adt.feature.group 8.0.1.v201012062107-82219)
Missing requirement: Android Development Tools 8.0.1.v201012062107-82219
(com.android.ide.eclipse.adt.feature.group 8.0.1.v201012062107-82219)
requires 'org.eclipse.gef 0.0.0' but it could not be found

Navigate to:

Help -> Install New Software -> Available Software Sites

and make sure that eclipse's release link is present and enabled.

For HELIOS version add and enable: http://download.eclipse.org/releases/helios

For GALILEO version add and enable: http://download.eclipse.org/releases/galileo


What follows now is just a review of all items to be installed. Hit Next ...

Android Plugin Install Review

Installation of Android Developer Tool Eclipse plug-in in progress.

Android plug-in installation progress

Click OK when unsigned software warning pops up. Once the installation is finished restart Eclipse.

3.4. Android SDK Installation

The last step of our installation section will belong to installation of Android SDK. First we need to download Android SDK starter pack from

Android SDK download link:

http://developer.android.com/sdk/eclipse-adt.html.

As a root user, navigate to /opt/ and initiate a download of Android SDK starter pack with a wget command:

NOTE: To keep this guide concise for Ubuntu and Fedora I do not use sudo command. Ubuntu users can change to root ( '#' ) with :

$ sudo bash 

or simply insert sudo in front of every command below.

NOTE: The wget link below may be outdated. Consult http://developer.android.com for any updates.

# cd /opt
# wget http://dl.google.com/android/android-sdk_r08-linux_86.tgz

Extract the content of Android SDK pack with

# tar xvzf android-sdk_r08-linux_86.tgz

At this point we need to install platforms and optional additional plug-ins or sample codes. Start Android SDK manager:

# android-sdk-linux_86/tools/android

And select SDK Platform Android 2.3, API 9 or choose any other platform depending on your desires. You may also wish to install some Samples code and additional Third-Party add-ons.

When you have selected all packages you desire click Install Selected.

android sdk and AVD manager menu

You will be prompted to Accept License. Click Accept All and then Install.

This concludes the installation part of this article.

4. Setting up Eclipse IDE with Android SDK

At this stage we need to join the Eclipse IDE with Android SDK as well as we will create an Android Virtual Device ( AVD ) to enable us conveniently test our new Android Application. To create Android Virtual Device execute a following command as a normal user. For example if you are going to develop Android Applications as a user "android" then log-in as a "android" user and execute:

$ /opt/android-sdk-linux_86/tools/android

Navigate to:

Virtual Devices -> Add

Insert a following information into:

  • Name: MyAndroidVirtualDevice
  • Target: choose any desired Android version and API level available to you from a drop down menu.

Feel free to change or add other values.

Create a new android virtual device

Once you click on "Create AVD" a new Android Virtual Device will be created in a following directory:

~/.android/avd

Close Android SDK manager.

The next step is to make the Eclipse IDE aware of our Android SDK installation. Start Eclipse and navigate to:

Window -> Preferences -> Android

and enter a location of your Android SDK installation into SDK Location Box and click apply:

Connect android sdk with eclipse

Press OK and we are done.

5. Writing a simple Android Application

Finally we are ready to write our first Android Application.

Open Eclipse and navigate to:

File -> New -> Project -> Android -> Android Project

and insert a following information to start a new Android Project:

Create a new android project

Press Finish.

On your left hand side you have a "Package Explorer. Use a package Explorer to navigate to:

HelloWorld -> src -> org.linuxconfig.helloandroid

From there double-click on HelloAndroidActivity.java

Replace an existing code:

 
package org.linuxconfig.helloandroid; 
 
import android.app.Activity; 
import android.os.Bundle; 
 
 
public class HelloAndroidActivity extends Activity {
    /** Called when the activity is first created. */ 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

With a following code:

 
package org.linuxconfig.helloandroid; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 
 
public class HelloAndroidActivity extends Activity {
    /** Called when the activity is first created. */ 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android \n linuxconfig.org");
        setContentView(tv);
    }
}

Save your Project with CTRL + S .

6. Testing new android application

Now that you have saved your new project you can attempt to run it by navigating to:

Run -> Run -> Android Application -> OK

This will now start your android virtual device "MyAndroidDevice" you have created previously.

NOTE: Allow couple minutes for Android Emulator to start as this things does no happen instantly.

Hello android application

If your application does not start after boot you may need to navigate with your mouse to:

HOME ( house icon ) -> All Apps Launcher Icon

and select "HelloAndroid" from the list as illustrated below:

android application launcher

Click on your new HelloAndroid application:

Start Hello Android Application

7. Conclusion

So much for a Hello Android application ! Mostly this guide was about installation of an Android Development environment on a Linux Operating system and that was the hardest part. Once you have it done it is easy to write some simple android applications and see the result using Android Virtual Device emulator. The purpose of Android SDK is just to make your life as Andorid Developer easy and get you results as fast as possible.

Next time we will explore more about Eclipse environment as well as we will look at some sample code provided by Android SDK. Do no forget to subscribe to RSS feed if you have not done so yet.

8. Appendix

8.1. Android Developer Tool on Ubuntu 10.10

This section is for those brave Linux users using Ubuntu 10.10 Maverick. Unfortunately Ubuntu 10.10 has a bug ( date of writing 06.01.2011 ) when installing Android Developer Tool into eclipse. The installation is all fine, however, the plug-in does not appear in the eclipse menu at all. Here are some links I have collected to help you guys some starting point on how to solve this problem. If you find some long term solution let me know so I can update this document. Thank you

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=587657
https://bugs.launchpad.net/ubuntu/+source/eclipse/+bug/633198


Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top