Monday, September 20, 2010

Installing Eclipse for Android on Ubuntu

In order to develop applications for Android, it is highly recommended by Google and the Android people to use the Eclipse IDE. When installing Eclipse, there are a few pitfalls I found.

First off, don't do as I did and just install Eclipse from the Ubuntu Software Center.  The Eclipse version in the installer is not the right one. You want to install version 3.5 of Eclipse, not 3.6.  If you have 3.6 installed, you need to uninstall it and go to 3.5, since there are reported problems with the Android Development Kit and version 3.6.  Eclipse 3.4 works as well.

Despite what it says on the Android SDK install page, you need to install the Java Development environment into Eclipse before installing the development tools. There is a little bug with Ubuntu 10.04 that prevents you from installing the development tools unless Java has been installed.  You will need the Java environment anyways, so install that first. Be sure you have the latest version of JDK 1.6 correctly installed before installing Eclipse for Java.  You can install Java with the Ubuntu Software Center, which makes this task rather painless. Just search for "Java" in the Software Center and install "OpenJDK Java 6 Runtime" from the list.

To get the best version of Eclipse, go to this site and download using one of the links on the right hand side of the page (Linux 32, do not try this in 64 bit). The downloaded file will be named eclipse-java-galileo-linux-gtk.tar.gz in your download folder. The file doesn't need to be installed, just unzipped into the right place. If you are lazy like I am, the easiest way to do this is graphically.  Go to your Ubuntu menu and open a Terminal from the Accessories menu. Open up Nautilus as a root user in the Terminal by typing sudo nautilus at the prompt in the Terminal window. After you supply your password, Nautilus will pop up, and you can then browse over to your /usr/share folder. Open another instance of Nautilus by clicking on places > home  in the Ubuntu menu.  Browse to the Download folder. Now find the eclipse tar file and drag it over to the /usr/share folder window. Once the file has been moved to the folder, right click on it.  Open the archive, then install all files to the original folders.  You should end up with an Eclipse folder in the /usr/share folder.

Now you need to install the Android SDK. Go to the SDK download page and click on the link for Linux (i386). Note there is no link for 64 bit environments. After the file has downloaded, do the same as before, and unzip the archive in the /usr/share folder.  Now you need to tell Eclipse where to find the SDK.

Again with your Nautilus, go to your /home/username folder and look for the file named .bashrc and right click on it.  Choose to open it with gedit. You need to add a path statement. If you have a regular install of Ubuntu, there won't be a PATH statement in the file.

Just after the first comments (comment lines have a # as the first character) in the bashrc file, add the line:

export PATH=${PATH}:/usr/share/android-sdk-linux_x86/tools

Now save and close the file.

You are almost done, you just need to set up Eclipse and the Android Development Tools (ADT). The installation of the ADT goes smoothly if all the setup work has been done correctly. Go to the installation page and follow the instructions for Eclipse 3.5 (Galileo). After you restart Eclipse, the ADT should be installed.  You can now install the Android platforms, so that Eclipse has a development target, and you can run Android emulations.

You need to browse with Nautilus over to the Android SDK folder we installed earlier. By the way, you need to be connected to the internet in order to install these files. Go to the tools subfolder, and then look for the file called android. Right click on it, and run it.  You should get the tools program with a listing of all available platforms for Android. Just select all of them and install them. You are done!

Have fun programming!

No comments:

Post a Comment