The One-Stop Android SDK/Eclipse/ADT Installer You Always Wanted

one_stop_sdk

Getting started with Android development can be a little daunting to newcomers.  There are a few different downloads and configuration steps, and quite a few fail points, especially if handcuffed by a zealous IT security team.  Wouldn’t it be nice if you could download and install one package and be ready to rock right out of the gate?  Those iOS developers have it so easy!  Well, now you can too, with the handy dandy Treehouse Android Development Bundle!

“But I like configuring proxies and assembling eight different components I’ve never worked with before!”

Says no one.  Admittedly, the documentation for setting up your Android environment has improved greatly, but it’s still a time-consuming and confusing process for new Android developers.

Feel free to download and try out our bundles for Mac OS X or Windows.  Check out Stage 1 of Build an Android Crystal Ball App.  Specifically, go to the page for the video Android Setup and the Crystal Ball Project and select the bundle that corresponds to your operating system from the Download links below the video.  Unzip the bundle, run the “initial_setup” script, and start coding!

If you want to set up a bundle for your own use or to share with students or a team, follow the instructions below.

How to Create Your Own Android Development Bundle

The goal here is to create a self-contained directory where all the components have relative paths to each other.  The main problem with using relative paths is that the relative path for the Android SDK in Eclipse breaks the AVD Manager. It won’t allow you to run existing AVDs or create new ones. Enter the “initial_setup” script! This little script should be run one time when the bundle is first unzipped.  It sets the Android SDK to an absolute path based on where the user unzips the package, and it also creates an initial AVD.

The key to the script is updating the Eclipse ADT Plugin preferences to use the absolute path of the Android SDK. This is accomplished with this line from the script below. Note that the path for the preferences file is relative to the workspace (and the workspace path is set as relative to the Eclipse installation).

echo com.android.ide.eclipse.adt.sdk=$sdk_path >> ./workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.adt.prefs 

Mac Instructions

Here’s what the final unzipped directory structure will look like. This is what we’re building:

Mac OSX Android Development Bundle Structure

  1. Create the root directory (android_dev_environment)
  2. Copy the Android SDK in (android-sdk-macosx)
  3. Copy in eclipse:
    1. Start with a clean version of Eclipse
    2. Run Eclipse. When prompted for a workspace, enter “../../../../workspace” (this will create the workspace directory in our root).
    3. Install the ADT Plugin via the “Install new software” option in Eclipse (https://dl-ssl.google.com/android/eclipse/). Restart when done.
    4. Change the Android SDK path in Eclipse preferences to be relative: “../../../../android-sdk-macosx”
    5. Install at least Platform Tools and the latest platform using the SDK Manager.
  4. Create initial_setup:
    #!/bin/bash
    # Set the Android SDK path in Eclipse. Must be the absolute; a relative path
    # does not work with the AVD Manager.
    cd "$(dirname "$0")"
    sdk_path=`pwd`/android-sdk-macosx echo
    "Setting Android SDK path in Eclipse..."
    echo com.android.ide.eclipse.adt.sdk=$sdk_path >> ./workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.android.ide.eclipse.adt.prefs
    echo "Android SDK path set."
    # Create a new AVD echo
    "Creating new AVD..."
    echo no | $sdk_path/tools/android create avd -n Android41 -t 1 --force
    echo "AVD created."
  5. Change permissions of initial_setup: chmod 754 initial_setup
  6. Zip up the directory!

Windows Instructions

Here’s what the final unzipped directory structure will look like. This is what we’re building:

Windows Android Development Bundle Structure

  1. Create the root directory (android_dev_environment).
  2. Install JDK 6 at android_dev_environment\Java.  In the installer, we only need to install Development Tools and the Public JRE (not the Java DB or Source Code).
  3. Install/copy the Android SDK in (android-sdk-windows).
  4. Copy in eclipse:
    1. Start with a clean version of Eclipse
    2. Edit eclipse\eclipse.ini. Add the following lines above the -vmargs line:
      -vm
      ..\Java\jdk1.6.0_35\bin\javaw.exe (make sure the jdk path is correct!)
    3. Run Eclipse. When prompted for a workspace, enter “../workspace” (this will create the workspace directory in our root).
    4. Install the ADT Plugin via the “Install new software” option in Eclipse (https://dl-ssl.google.com/android/eclipse/).  Restart when done.
    5. Change the Android SDK path in Eclipse preferences to be relative: “..\android-sdk-windows”
    6. Install at least Platform Tools and the latest platform using the SDK Manager.
  5. Create initial_setup.bat:
    REM Set the Android SDK path in Eclipse. Must be the absolute;
    REM  a relative path does not work with the AVD Manager.
    cd > temp.txt 2>&1
    set /p sdk_path= < temp.txt
    del temp.txt
    set sdk_path=%sdk_path%\android-sdk-windows
    set sdk_path=%sdk_path:\=\\%
    set sdk_path=%sdk_path::=\:%
    echo “Setting Android SDK path in Eclipse...”
    echo com.android.ide.eclipse.adt.sdk=%sdk_path%>> .\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\com.android.ide.eclipse.adt.prefs
    echo “Android SDK path set.”
    REM Create a new AVD
    echo “Creating a new AVD...”
    echo no | .\android-sdk-windows\tools\android create avd -n Android41 -t 1 --force
    echo “AVD created.”
    pause
  6. Reset the eclipse.ini -vm path to a relative one (see Step 4B above). Apparently when you run Eclipse it updates this path to an absolute value.
  7. For 64 bit Windows, we also need to edit the find_java.bat file in the Android SDK so that it finds the Java installed with the bundle. Add the following lines to android-sdk-windows\tools\lib\find_java.bat (before it runs its own check that starts with the comment “rem Check we have a valid Java.exe…”):
    set java_exe=%~dp0\..\..\..\Java\jdk1.6.0_33\bin\java.exe
    set javaw_exe=%~dp0\..\..\..\Java\jdk1.6.0_33\bin\javaw.exe
    if defined javaw_exe goto :EOF
  8. Zip up the directory!

Note: Running the initial_setup script on a Mac or a PC multiple times does not hurt anything. The dev environment will break if you move the whole directory after running initial_setup, but running initial_setup from the new location will fix it. It might help to include a README file with the bundle explaining this and any other tips or troubleshooting advice you want to share.

Anybody have any similar solutions for Linux or another IDE like IntelliJ?  If so, leave a note in the comments!  :)

Free Workshops

Watch one of our expert, full-length teaching videos. Choose from HTML, CSS or WordPress.

Start Learning

Ben Jakuben

I'm a dad to a few, husband to one, son to two, brother to one, and friend to many. I spent nine years in software development before finding my dream job with Treehouse. Lately I've been focused on mobile development (primarily Android) as well as how to be a better father/husband/son/friend. Firmly committed to the belief that the world is evolving to a better place. Find me on Twitter @benjakuben.

Comments

5 comments on “The One-Stop Android SDK/Eclipse/ADT Installer You Always Wanted

  1. I and my team are planning to develop an application. I have already downloaded and installed eclipse juno, sdk and required plugins/updates. It took lot of time for me to do all these (download speed – 45 to 60kbps). Same operations need to be performed in others (my team) system too. Can I just copy all the files in C drive (sdk & workspace) and paste it in others C drive? do you think it will work? If it doesn’t Is their any other way?

    • Yes and no. Eclipse is a totally localized installation, which means you can copy the “eclipse” directory and paste it anywhere else to run, including other computers. The SDK is also localized, so you can copy that around as well. However, once Eclipse and the SDK are linked, that path is stored as a hard-coded value. So moving things around or to other computers will break that setting. That’s why I have this bundle approach that runs a small script to fix this problem.

      Your best bet might be to download the latest bundle from the Android Developer Site (http://developer.android.com/sdk) and then just copy the zip file around. Good luck!

  2. Hey Ben, I’m having a problem installing your bundle on a Windows 32 bit system. It looks like the eclipse and java in those folders are for 64 bit because the initial_setup program gives an incompatibility error.

    I’ve tried manually replacing the two with 32 bit versions, but haven’t had much luck.