Installing Eclipse and the Android SDK on Ubuntu 10.04

I had been playing around with installing the Eclipse IDE (arguably the best Java IDE around) and the Android SDK on my previous Ubuntu installation and basically made a hash of it a few times. Having refined my process I’ve decided to write it down so that I don’t forget ;-) Following my clean installation of Ubuntu 10.04 I needed to get my development environment sorted out, and this meant installing Eclipse and the Android SDK and then wiring them both together.

When downloading the IDE I opted for the ‘Eclipse IDE for Java Developers’ because essentially Android is a set of libraries built on top of Java, so it seemed like a good place to start. Note that I’m using Eclipse 3.5 (Galileo) for my development.

The installation process for Eclipse is a simply case of extracting the downloaded archive into a suitable location, I’ve created a folder called Applications in my /home/Develop directory and extracted the archive into it. Double clicking on the eclipse executable file kicked off the IDE which loaded quite quickly after prompting my for a workspace location – I just kept the default.

So that’s Eclipse sorted, now what about the Android SDK?

After downloading the SDK it too is installed by simply extracting into a suitable location, again I extracted it into my /home/Develop/Applications folder. But we are not quite finished yet – we need to use the SDK Manager to download and install at least one Android development platform first (read the ‘SDK Readme.txt in the folder when you extracted the SDK for more details). This is a simple case on executing the [SDK Folder]/tools/android file either via the command line for by double-clicking it. The SDK and AVD Manager will now load and I simply selected the ‘Available Packages’ option, selected everything in the right-hand pane and clicked on ‘Install Selected’. After a length installation process I was done – this is my SDK/AVD Manager after the installation completed.

SDK and AVD Manager

So that’s it, we’re there yes? Well no, not yet. In the Windows world we are used to installations detecting the presence of IDEs or vice-versa and everything just working once the installer finishes. Well Linux is not like that we need to so some additional configuration before we can get coding; in fact Eclipse/Android installation is pretty much the same on all platforms, so it’s not just an Linux thing.

The first thing to do is to install the Android ADT (Android Developer Tool) plugin into Eclipse – which you’ll be happy to hear is a semi-automatic process.

  • Start Eclipse and select ‘Install New Software’ from the Help menu.
  • Click the ‘Add’ button next to the “Work With” dropdown list
  • Enter a suitable name for this resource, e.g. Android Developer Tools, and the following URL into the location:
  • Click Ok

Eclipse will now search for the ADT plugin and all things being equal will display a screen similar to this:

ADT Install Screen

Select the ‘Developer Tools’ checkbox (which

will select the DDMS and Development Tools beneath it) and click next. After agreeing to the Licence Agreement (which of course you read first) click Finish and the installation will proceed.

You may get a security warning at this point because the packages are apparently unsigned but I just clicked OK to carry on. All things being equal you will be prompted to restart Eclipse and the installation process is then complete.

Selecting File | New you will see ‘Android Project’ displayed and clicking it will display the following window:

New Android Project Dialog

Now I’m still new to Android development so I’ll not inflict my poor knowledge of what you need to enter into this screen – you probably know better than me at the moment anyway ;-)

What I can say is that I managed to complete the obligatory ‘Hello World’ application from my copy of ‘Professional Android 2 Application Development’ book by Reto Meier so I must have it set up somewhere near right.

Android Hello World


Install Eclipse with Sun JDK Ubuntu

Eclipse is an open source community whose projects are focused on building an open development platform comprised of extensible frameworks, tools and runtimes for building, deploying and managing software across the life cycle . A large and vibrant ecosystem of major technology vendors, innovative start-ups, universities, research institutions and individuals extend, complement and support the Eclipse platform.

Install Eclipse with Sun JDK in Ubuntu

sudo apt-get install eclipse sun-java6-jdk

This will install the required packages, however, Eclipse will run very slowly since it will be using GNU’s java, not Sun’s. We now need to make Sun’s java the default.

sudo update-java-alternatives -s java-6-sun

Next, edit the JVM configuration file

sudo -b gedit /etc/jvm

and add the following to the top of the file


There is a bug right now were Eclipse ignores Ubuntu’s java-common settings and uses its own (bug 45347). To work around the bug, you need to edit Eclipse’s java_home file

sudo -b gedit /etc/eclipse/java_home

and add


to the top of the file.

Lastly, if you have lots of memory you may want to increase the heap size (warning: If you make the heap size too large then parts of eclipse will continuously swap in and out.).The settings can be altered by editing the eclipse.ini file.

For feisty users:

sudo -b gedit /usr/lib/eclipse/eclipse.ini

The argument Xms refers to the minimum heap size and Xmx refers to the maximum heap size.

Creating your first Eclipse e4 Application

Eclipse released on the 29 July 2009 the tech preview version 0.9 of Eclipse e4, which can be downloaded here.

I wasn’t able to find a description how to create an new application based on E4. Starting from the CVS example is possible but I wanted to start from scratch. After several failed attempts to create an E4 application I believe I have found a way to create an E4 application. I assume others will have similar problems so I wanted to share my experience.

To follow this description you need to have knowledge how to develop Eclipse Plugins in Eclipse 3.5 or earlier. Check out this Eclipse Plugin Development Tutorial.

So lets get started with e4.

Download e4. Extract it and start it is similar to older Eclipse versions.

Currently there is no wizard which creates a working scaffold of an E4 application. We will therefore use the exsting plugin templates.

Create a new Plugin project “de.vogella.e4.first”. Do not select “Generate an activator”, nor “This plug-in will make contributions to the UI” nor “Would you like to create a rich client application”. Do not select a template. Press finish.


This will open the Plugin Perspective, switch here to the Package Explorer to see your new project.

Create the package “de.vogella.e4.first”. The result should look like the following.


Select your MANIFEST.MF and add the following dependencies to your plugin.

01 Manifest-Version: 1.0
02 Bundle-ManifestVersion: 2
03 Bundle-Name: First
04 Bundle-SymbolicName: de.vogella.e4.first;singleton:=true
05 Bundle-Version: 1.0.0.qualifier
06 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
07 Require-Bundle: org.eclipse.ui,
08 org.eclipse.core.runtime,
09 org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
10 org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.9.0",
11 org.eclipse.e4.ui.workbench.renderers.swt.contributions;bundle-version="0.9.0",
12 org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.0",

You need (some of) these plugins for the usage of E4 features.

Add the following extension points. I noticed that for some of the features you have to modify the plugin.xml directly as the UI does not support them. But you have to create the plugin.xml via the MANIFEST.MF file; as I created it directly as a new file I received a strange system behavior.

01 <?xml version="1.0" encoding="UTF-8"?>
02 <?eclipse version="3.4"?>
03 <plugin>
04 <extension
05 point="">
06 <part
07 class="de.vogella.e4.first.views.View1"
08 label="My first E4 View"
09 parentId="org.eclipse.e4.ui.tags.navigation">
10 </part>
11 </extension>
12 <extension
13 id="product"
14 point="org.eclipse.core.runtime.products">
15 <product
16 application="org.eclipse.e4.ui.workbench.swt.application"
17 name="vogella">
18 <property
19 name="appName"
20 value="vogella">
21 </property>
22 <property
23 name="applicationXMI"
24 value="de.vogella.e4.first/Application.xmi">
25 </property>
26 </product>
28 </extension>
30 </plugin>

“” is a new extension point by which you can define your view parts, formally known as views and editors.

The extension point “org.eclipse.core.runtime.products” has a new parameter “applicationXMI”. This is a parameter to the model of your UI. We came to this later. You also do not define your own application; we use “org.eclipse.e4.ui.workbench.swt.application”.

Create a product configuration called “vogella.product”. This is similar to Eclipse 3.5; see here for a description: Eclipse Product Configuration.


Make sure you select “org.eclipse.e4.ui.workbench.swt.application”.


Add as dependency to your product the plugin “org.eclipse.e4.ui.workbench”. Add also the plugin “de.vogella.e4.first”.
Press “add required plugins”.

Create the following two classes:

1 package de.vogella.e4.first.handlers;
3 import org.eclipse.e4.workbench.ui.IWorkbench;
5 public class ExitHandler {
6 public void execute(IWorkbench workbench) {
7 workbench.close();
8 }
9 }


01 package de.vogella.e4.first.views;
03 import;
04 import org.eclipse.jface.layout.GridLayoutFactory;
05 import org.eclipse.swt.SWT;
06 import org.eclipse.swt.layout.GridData;
07 import org.eclipse.swt.widgets.Composite;
08 import org.eclipse.swt.widgets.Label;
09 import org.eclipse.swt.widgets.Text;
10 import;
12 public class View1 implements IDisposable {
14 public View1(Composite parent, final IEclipseContext outputContext) {
15 Label label = new Label(parent, SWT.NONE);
16 label.setText("E4 is new");
17 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
18 gridData.horizontalIndent = 20;
19 label.setLayoutData(gridData);
20 Text text = new Text(parent, SWT.NONE);
21 text.setText("and different");
22 GridLayoutFactory.fillDefaults().generateLayout(parent);
23 }
25 public void dispose() {
27 }
28 }

You need a model for your application. In the parameter “applicationXMI” we earlier defined that this model will be “de.vogella.e4.first/Application.xmi”. Create the file Application.xmi with the following content.

01 <?xml version="1.0" encoding="ASCII"?>
02 <application:MApplication xmi:version="2.0" xmlns:xmi="" xmlns:xsi="" xmlns:application="">
03 <windows name="Main" x="100" y="100" width="800" height="600">
04 <menu>
05 <items xsi:type="application:MMenuItem" name="File">
06 <menu>
07 <items xsi:type="application:MMenuItem" id="" name="Exit" command="//@command.0"/>
08 </menu>
09 </items>
10 </menu>
11 <children policy="VerticalComposite">
12 <children xsi:type="application:MSashForm" policy="HorizontalSash">
13 <children xsi:type="application:MStack">
14 <children xsi:type="application:MContributedPart" iconURI="" name="My View" tooltip="My first View" URI="platform:/plugin/de.vogella.e4.first/de.vogella.e4.first.views.View1"/>
15 </children>
16 <weights>30</weights>
17 <weights>70</weights>
18 </children>
19 </children>
20 <handlers id="" URI="platform:/plugin/de.vogella.e4.first/de.vogella.e4.first.handlers.ExitHandler" persistedState="" command="//@command.0"/>
21 </windows>
22 <command id="application.exit" name="Exit"/>
23 </application:MApplication>

This is the EMF model which defines your UI. Eclipse should display this model in a EMF editor so that you can investigate it. In this model you find your view and command definition. The content can be viewed via the properities view.


Now start your application from your vogella.product. Starting it directly from the plugin.xml will not work (easily).

If you receive the error “org.eclipse.core.runtime.AssertionFailedException: null argument:-applicationXMI argument missing” check you plugin.xml. E4 created in several cases twice the products entry.

You should be rewarded ;-) with this user interface:


With this first application I hope you can started using the E4 advanced features, e.g. CSS styling, etc.

My final thoughts: Eclipse e4 has already amazing capabilities for a tech review release. The new modeled UI removes the need for a lot of boilerplate code.

More Information

Eclipse e4 new look and feel – Around the world

Eclipse e4 M4 has introduce a new look and feel for the tabs in the workbench. See Eclipse e4 M4 New and Noteworthy. Unfortunately the news and noteworthy document did not give information how to enable this feature.

The e4 mailing list has recently discussed this topic and Remy Suen was kind enough to provide this information. To turn this feature on you have to add the tag “newtablook” to your PartStack.

For example if you create an new e4 application with the e4 wizard you can add this tag via:

1 <children xsi:type="application:PartSashContainer" xmi:id="_vTa8kiuFEd-PeMLywHTM-g" id="_vTa8kiuFEd-PeMLywHTM-g">
2 <children xsi:type="application:PartStack" xmi:id="_vTa8kyuFEd-PeMLywHTM-g" id="_vTa8kyuFEd-PeMLywHTM-g">
3 <tags>newtablook</tags>
4 <children xsi:type="application:Part" xmi:id="_vTa8lCuFEd-PeMLywHTM-g" id="_vTa8lCuFEd-PeMLywHTM-g" label="Main"/>
5 </children>

This lead to the following result:

Compared to the “old” look and feel.

For this topic see also Bug 305147 which discusses to move this feature to the CSS styling capabilities.

Junit in Eclipse

Unit testing is defined as “ Each module is tested alone in an attempt to discover any errors in its code ”. Its always a good practice to test each unit of your project independently as it saves time and effort while integrating the modules.

JUnit provides close relationship between testing and development. As developers write the code, they use the JUnit test runners to verify how much it deviates from the intended goal. Normally it is a standard practice that the code developers themselves write unit tests for their code.

First step is to put “ junit.jar ” on the build Path. Go to project properties and click “ Java Build Path ”. In the Libraries tab click “ Add External JARs ” and then browse to “ junit.jar ”.

Suppose we want to test method called “ getSmallest() ” in class “ Test.MainClass ”. This method takes an integer array as input argument and returns smallest integer from that array. We will write “ TestCase ” to test this using Junit.

package Test;

import java.util.*
public class MainClass {

public static void main(String[] args) {


public static int getSmallest(int arr[]){


 	return arr[0];



Right click “ project name ” and click “ New ” – > “ Junit Test Case ”. New JUnit Test Case window will open. Name the test case and select class for which you are writing the test case. In my case, I selected Test.MainClass. Click Next.

Now we have to select the methods from the chosen class for which test stubs will be generated. In my case, I selected “ getSmallst(int[]) ”. “ Click Finish ”. Test stubs for the method is generated but we have to write a little code to test it.

Review the code below:

package Test;

import junit.framework.TestCase;

public class test_case_getSmallest extends TestCase {

public test_case_getSmallest(String arg0) {



protected void setUp() throws Exception {



protected void tearDown() throws Exception {



public void testGetSmallest() {

MainClass o = new MainClass();

 	int[] myarray ={100,200,30};

int val;

 	if((val = o.getSmallest(myarray)) != 30)


 		System.out.println("Shortest value returned is :
" + val);

 		fail("Not right result.");




To run it, right click the test case ( and click “ Run As ” – > “ JUnit Test ”. Test will run and the results will be shown. In my example, I got the following results.

Now to see failures. We changed the “ testGetSmallest() ” code as

public void testGetSmallest() {

MainClass o = new MainClass();

 	int[] myarray ={100,200,30};

int val;

 	if((val = o.getSmallest(myarray)) != 100)


 		System.out.println("Shortest value returned is :
" + val);

 		fail("Not yet implemented");



Output I was shown is:

In this example,we are just testing a method using a simple test case. We can test more than one methods using same test case as well. For instance, we could have more than one methods in our class “ MainClass ” and then more than one test stubs in our test case “ test_case_getSmallest() ”.

Eclipse ideas for Google Summer of code 2010

My favorite time of year is about to start soon when it comes to open source development, Eclipse’s involvement with the Google Summer of Code (GSOC) program.

All people involved in the Eclipse community should post their ideas here. It’s a good time to start posting ideas, as students will start looking at mentoring organizations in mid March.

There is little downside in participating in this program in my opinion. As an GSOC mentor, you get the rewarding opportunity to mentor a student in the ways of Eclipse and open source. As a student, you get Eclipse experience and paid for your contributions!

In the end, the whole open source community benefits.

Install Eclipse in Ubuntu

Eclipse 3.5, codenamed “Galileo,” was released this week! While there is a team actively working on building an Ubuntu deb package, they do not yet have a package yet for Eclipse 3.5. I put together some super simple instructions for installing Eclipse 3.5.

I am going to perform a per-user installation into my home-directory. If multiple people use eclipse on the same computer, you may want to modify these instructions to install into /opt/. I am going to put the installable in ~/bin/packages/eclipse3.5. First, create the installation directory (change according to your own tastes)

mkdir -p ~/bin/packages
cd ~/bin/packages

Now download the appropriate tar.gz file from eclipse. I am going to grab them from Amazon’s Cloudfront.

For 64-bit Ubuntu:


For standard 32-bit Ubuntu:


Now unzip, and rename the directory (I want multiple versions of Eclipse):

tar xzvf eclipse-java-galileo-linux-gtk*.tar.gz
mv eclipse eclipse3.5

Great, almost there. I am going to create a file so that I can launch eclipse from the command line. Create a new file ~/bin/eclipse, and in that file, put:

`~/bin/packages/eclipse3.5/eclipse -vmargs -Xms128M -Xmx512M 
-XX:PermSize=128M -XX:MaxPermSize=512M &> /dev/null` &

(You can later change these values if you get out of memory issues from Eclipse.) Lastly, make the file executable:

chmod u+x ~/bin/eclipse

Install plugins

Yet again, Eclipse has changed its update manager (each time it gets better). I am going to add a few plugins for Python, Clojure, and Mercurial. If you go to Help > Install new software, click the “Available Software Sites” link, and add your update sites. For me they include:

Add Icon to the Panel I like having an icon on my panel to quickly launch Eclipse, like so:

To do so, right click on your panel in a place with no other panel tool. Select “Add to Panel” then create a “Custom Application Launcher”. You can enter /home/<USERNAME>/bin/eclipse (put in your username) as the command to run, and if you click the icon on the left, you can use the Eclipse icon in ~/bin/packages/eclipse3.5/.