Wednesday, November 30, 2011

So Now You Tell Me!: Setting Up Eclipse for Android Development on Windows

Note: I've toyed with creating this "So Now You Tell Me!" series for a while. The goal is to create useful how-to posts for tasks that I can't find definitive instructions for anywhere on the web.

I've talked to a handful of developers that have Android phones who want to dabble in developing an application, but find it a bit difficult to get the development environment up and running. The google page for installing the Android Developer Toolkit is a decent start, but assumes you have the Java and eclipse parts down already.

My goal here was to create the "missing manual" for bootstrapping an Android development environment on Windows (Windows 7 in this case). I really try to leave no stone unturned, without adding so much additional detail as to make it hard to follow. I'll update it as I learn more, or as the Android SDK evolves. Please comment below if you find an error, or information that may be missing!

So, here we go...

Installing the JDK (Java Development Kit)



The first thing we need to do is to install the java development kit and runtime on our computer.  You can find the latest stable download at:

http://www.oracle.com/technetwork/java/javase/downloads/index.html


The full JDK installer is needed, just the JRE will not be enough.



1. Find the windows EXE installer for your platform (32-bit or 64-bit) in the list and download it to your computer

2. Run the installer and follow the default prompts until it completes


Installing the Eclipse IDE

1. Open http://www.eclipse.org/downloads/ in a browser

2. The order and names of packages change fairly frequently. Select the "bare bones" package as I call it, usually called something like "Eclipse IDE for Java Developers" (Make sure you select the proper platform - 32-bit or 64-bit).  As of the time of this writing the latest version available for Windows is "Indigo SR1".



3. You will be prompted to download a zip file with the eclipse software.  Save it to disk then extract it to an empty folder on your computer.

4. From the root of the extracted eclipse folder, run eclipse.exe


5. Eclipse has the idea of top level "workspaces", which are basically folders which contain any number of eclipse projects that serve as default starting points when opening eclipse.  You'll be prompted to create a new workspace the first time.  Enter the name of an empty folder on your computer where you want your workspace to reside.



6. When eclipse has started, close the initial "Welcome" tab to see the initial view (or the initial "Perspective" in eclipse jargon).

7. Close eclipse for now, we'll come back to it later


Installing the Android SDK

The Android SDK install can be found at:

http://developer.android.com/sdk/index.html

I always select the EXE installer for Windows.


1. Download the Android SDK EXE installer (versioned at 'r15' at the time of this writing.  Google increments this number with every new release of the Android SDK and that number is what is used when selecting which SDK version to target in your application - more on that later)

2. Run the executable installer and follow the default prompts

3. At the end, choose to run the SDK Manager which will help you download the various SDK versions that you may want to target for your application





Using the Android SDK Manager

When the SDK manager first starts, you'll be prompted with a list of SDK versions to download.  I usually research what the current distribution of Android versions is out in the wild, and then install all SDKs that will cover the vast majority of the handsets.  (At the time of this writing I usually install all versions back to 2.1).

1. Select all the SDK versions that you may want to support



2. Click Install X Packages, where X is the number of selected SDK packages.

3. You will be prompted with a list of selected packages - click Install

Warnings:
  • Installing all the selected versions may take a while
  • If you have an aggressive firewall installed you may see warnings of attempts to connect to multiple local ports - allows these connections or you may have problems

One last thing you will need to do is create an emulator image (AVD - Android Virtual Device) to run your apps in during development.  To accomplish that do the following:

1. In the SDK Manager, select Tools > Manage AVDs from the menu bar

2. Click the New... button

I usually enter the following values:

Name: PlainXX where XX is the version of Android I am targeting (e.g. Plain21 for Android 2.1)

Target: Pick the lowest version of Android you want to support (2.1 in my case). Yes, more recent versions have more APIs and features, but you'll exclude yourself from large market segments if you pick the most recent version. If you plan on creating a tablet-specific version as well, then create a separate AVD targeting version 3.0 or above later on.

Size: Unless you are doing heavy SD Card data storage in your app, you can pick a relatively low SD card size.  I usually pick 40 MB.

Snapshot: This persists emulator state between test runs.  I usually leave this unchecked as using it decreases emulator performance on startup.

Hardware: I usually go with the default hardware settings.  If you are targeting a specific set of hardware features (resolution, etc), do it here.



3. Click Create AVD then exit the SDK Manager



Installing the Android Developer Toolkit (ADT) Plug-in For Eclipse

The Android Developer Toolkit (ADT) is a plug-in for eclipse that provides project types and tools to develop Android applications more quickly.  It can be found at: http://developer.android.com/sdk/eclipse-adt.html

The instructions to install the ADT are on the link page, but here they are for completeness sake:

1. Start eclipse again

2. Select Help > Install New Software... from the menu

3. Click the Add button in the top right-hand corner

4. In the Add Repository dialog, type ADT for the name and in the Location box type: https://dl-ssl.google.com/android/eclipse/

5. Once the item is fully loaded, mark the check box next to Developer tools and click Next



6. You will be shown a list of items that will be installed, click Next

7. Accept the license terms and click Finish

8. When the installation is complete, restart eclipse

9. When eclipse restarts, you will be prompted to install a new SDK or select an existing one.  Since we already installed the SDK and downloaded all the revisions we need, choose Use Existing SDKs, and enter the root folder of the Android SDK (Usually "<System Drive>:\<Program Files Folder>\Android\android-sdk".  e.g.:

C:\Program Files (x86)\Android\android-sdk



10. Click Next

You're now ready to create your first Android application!



Creating an Android application project

To create an Android project in eclipse:

1. Select File > New > Other from the menu bar

2. In the resulting dialog, under Android select Android Project



3. Click Next

4. Type in a project name and click Next

5. Select the target Android version (again, the lower the better - 2.1 in my case)



6. Click Next

7. Lastly, type in a java package name, usually in the form like this: com.companyname.product, but you can pick whatever serves you best.

8.  Click Finish


Now you are ready to start coding!

2 comments:

  1. By read your post I came to know how we can built Android development windows.This is one of the specific post.
    Android app developers

    ReplyDelete
  2. After struggling for over a week with the dreaded "requires 'org.eclipse.wst.sse.core 0.0.0' but it could not be found" error I found these instructions. Five minutes later and I'm running Eclipse with the ADT plug in. If you're ever in Tucson I'll buy you a beer. Thanks man.

    ReplyDelete