Build Overview‎ > ‎

Building the Deprecated Eclipse-Based Tools

Note that The Eclipse ADT plugin and tools have been deprecated in favor of Android Studio.

This document describes how to build all the Eclipse support for Android, as well as how to configure all the source code such that you can edit, run and debug the Android plug-ins from within Eclipse.

Setup
  1. Make sure you have followed the basic instructions in our overview page.
  2. Build the ADT distribution from the command line: $ cd $ANDROID_SRC; mkdir -p out/dist; ./sdk/eclipse/scripts/build_adt.sh out out/dist 123. This should generate the full ADT inside the folder out/dist
  3. Download and Launch Eclipse for RCP development
  4. [Optional] Setup the target platform. By default, the target platform is set to be the same platform that you are developing with. This is fine unless you are missing dependencies such as CDT (required by the NDK plugin)
    1. Open Window | Preferences | Plugin Development | Target Platform
    2. Create a new target platform (select "Nothing: ...", pick a name like AdtPlatform), and add each of the following folders as a software p2 repository by clicking on Add > Directory and in location choosing:
      1. out/host/maven/target/{cdt, egit, emf, gef, jdt, pde, platform, wtp}
    3. Select the newly created target platform as your default target platform. The plugins will be compiled against this platform
  5. File | Import, choose Existing Projects into Workspace, and import: 
    1. Import all the plugins inside sdk/eclipse/plugins
    2. tools/base
    3. tools/swt
  6. Close some unnecessary projects (if you don't need to develop them; in particular DeviceConfig, NotificationStudio and SdkControllerApp are independent Android projects which won't work unless you have the ADT plugin installed in your host IDE (and these are independent of all the other tools). Similarly for me I ran into some compilation issues with ant-tasks, chimpchat, the hierarchyviewers and plugin-ndk, so I just closed those. When you do that, make sure that any refactoring operations you do don't also need edits in projects you are no longer looking at.)
  7. Setup the classpath variables ANDROID_OUT_FRAMEWORK=prebuilts/tools/<platform>/swt and ANDROID_SRC=/root/of/android/tree
  8. Ignore errors in lint-api and lint-checks (or apply https://android-review.googlesource.com/#/c/101089)
  9. There should already be two launch targets created (monitor and adt). You should be able to compile and run them, ignoring any compile errors in the test plugin.
Rebuilding tools
If you happen to rebuild the tools (tools/base or tools/swt), then you should do the following from the command line in order to refresh the bundled dependencies inside the Eclipse plugins.

$ cd $ANDROID_SRC
$ rm -r out/repo
$ ./tools/gradlew -b tools/build.gradle publishLocal
$ ./tools/gradlew -b sdk/eclipse/build.gradle copydeps

Run and Debug

There should already be a couple of run configurations defined (adt and monitor). If you try to run/debug and execution fails with the message
java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Display
then follow the accepted answer in http://stackoverflow.com/questions/17527096/eclipse-kepler-startup-error-noclassdeffounderror-org-eclipse-swt-widgets-disp (e.g. edit the run config, find the swt plugins in the plugins tab and make sure the one you need is selected).

You should now be able to run the ADT - it will invoke a second instance of Eclipse, where all the Android tooling is baked in. The first thing you need to do is point the tool to a version of the SDK. Open the Preferences panel, and in the Android panel go to the text field where you can point to an SDK root. If you have downloaded versions of Android in the past, you can point to the root containing all of the different platforms here. 

For Linux and Mac users: You can either download an official release of the SDK to use with ADT or you can build your own local SDK -- when you ran "make sdk" earlier you built a trunk version of the Android SDK (from here on referred to as "AOSP", which stands for Android Open Source Project).  Therefore, you can point to your build output here -- and as you continue pulling down new changes and rebuilding the SDK, your Eclipse target will also use the latest and greatest. 
To point to it, use <your tree>/out/host/<architecture>/sdk/android-sdk_eng.<username>_<platform>/.
That exact path depends on your architecture and user name. So open the file chooser and drill down, first to out, then host, then your os and architecture, then sdk, and then some directory which contains "android-sdk_eng", your username and your platform.  Hit OK.

For Windows users:  The easiest thing to do is to use an official installation of the SDK (if you need to customize the Android platform yourself the only alternative is to do a linux or mac build of the SDK and then copy it over on your Windows machine; if you do that you might as well develop on ADT on the mac or linux box where you modify the platform.)


After a brief pause you should now see a platform listed in the listbox in the Android panel, and it will identify itself as version "AOSP". If you instead point to officially released versions of Android, you'll see versions like "5", "6" and "7". The reason we don't use a number for the trunk version is to prevent you from accidentally building an app compiled against this trunk version, and then releasing it on the market.

Now that you have your Android versions configured, you can create a new Android project. Do New > Android Project, and in the New project dialog, you need to go and choose the AOSP platform in the platform listbox.  Fill out the dialog. The only trick is that it asks you for a "Min SDK Version", and here you should again type "AOSP".  You can now go and try for example the Layout Editor, by opening res > layout > main.xml.

We're working actively on the layout editor, but as you can see we could use help in lots of areas, from feature development, to icon work, to bug fixing, to bug reporting!

To stay up to date, just go to the command line, type "repo sync", wait for a while, and then redo the make steps (source build/envsetup.sh, lunch sdk-eng, make sdk, create_symlinks), and reopen Eclipse and rebuild all. If you get a build error, you can wipe out the entire out folder to build from scratch, but I rarely have to do that.

You can add additional Android platforms, such that you can choose which platform to use for WYSIWYG rendering (just like you can already switch theme, orientation, etc):



This is a new feature added just in the last couple of days. It lets you target older platforms but visually work with newer platforms, and quickly switch between them to see how your layout looks on different platforms.  Of course, to use this you need to point your root Android tree to an install containing multiple platforms. If you do add additional platforms, make sure you copy older platforms (android-6, android-7, etc) into the platforms/ folder of the newly built SDK, rather than the other way around. This is necessary because the directory structure changed recently.

Edit

Now that you can build and run, let's take a look at the source code. The main Eclipse project to look at is the "adt" project, which is the Eclipse plugin.

First, you can configure your editor to use our custom dictionary to help the spell checker recognize words that are in our comments but are not in the default Eclipse English dictionary.  Search for Spelling in the options dialog, and add sdk/eclipse/dictionary.txt as the "User Defined Dictionary" path.

Second, if you will be doing any editing of the source code, make sure you configure your editor to use our formatting preferences and our import order. Open the Java Code Style dialog, and for the formatter, import development/ide/eclipse/android-formatting.xml . For Organize Import, import development/ide/eclipse/android.importorder . The code style for the Android source code base is document in http://source.android.com/source/code-style.html.

***

That's it! You should now be able to get the source code, build, edit, run and debug the Android IDE tools!