Multiple Android SDKs in Eclipse

The traditional and supported way to accomplish this is via the use of multiple workspaces, each one configured for a different SDK revision.

However, you can accomplish this in an alternative eclipse fashion, using Eclipse "Installed JREs".

Here's what it looks like from a Packaging Explorer point of view...

android-jre-package-explorer.png

Pay attention to the project definitions and icons here ...

  1. flagged as Android projects (the lowercase 'a' icon on the project folder)
  2. not using the nebulous 'Android Library' build path library

You can start using this technique by specifying a few Installed JREs in your Window / Preferences.

A Typical View when first starting out ..

android-jre-1.png

Lets start adding a new Android JRE.

  1. Choose 'Add' button.
  2. You will see the "Add JRE / JRE Type" dialog.
  3. Select "Standard VM" from the options.

android-jre-2-add-jre-dialog.png

Select 'Next' button and you are presented with an empty "Add JRE" dialog.

  1. Browse to a "JRE Home" that is a Sun (not IBM, not GCJ) Java 1.5 (not 1.4, not 1.6) location.

The dialog will auto populate based on information in the browsed JRE Home.

You will see something like the following ...

android-jre-4-add-jre-def-default.png

Now you need to make some modifications here ...

  1. Remove all of the JRE System Library entries in the dialog.
  2. Change the "JRE Name" to something useful, like "Android 1.0"
  3. Choose "Add External JARs..." and pick the Android.jar from your SDK installation directory.

You should have something that looks like this ...

android-jre-setup-1.1.png

TIP: You can even specify an Android-src.jar to help navigate into the source code during debugging.

Vote for Issue 979 - Please provide a simple android-src.jar for debugging in eclipse if you want to see this jar be part of the official SDK releases.

Example of this setup (I built my own source jar) ...

android-jre-setup-1.0.png

Now continue to setup the other Android SDKs you have and you might end up with something like this ...

android-jre-example.png

We're almost done.

Now we need to tell our projects to use these newly created Android JREs.

  1. Open up the project's properties view.
  2. Goto the "Java Build Path" entry.
  3. Navigate to the "Libraries" tab.
  4. Remove any Library entries for "Android Library" or "JRE System Library".
  5. Now use the "Add Library" button.
  6. Pick "JRE System Library" from the options.
  7. Push "Next" button
  8. And pick an "Alternate JRE" of the Android Library you created earlier.
  9. Save your changes.

android-jre-add-library-jre.png

android-jre-alternate-jre.png

You are now done.