Wednesday, November 30, 2011

Building the ADT Plugin for Eclipse


ADT Plugin Revisions

Notes about successive releases of the ADT Plugin can be found at http://developer.android.com/sdk/eclipse-adt.html.
Currently the last revision is ADT 15.0.1 (November 2011)
Usually ADT Plugin has dependencies with SDK Tools (located at <sdk>/tools directory of sdk). So do not forget to check the dependency and update to corresponding SDK Tools version after updating ADT Plugin.

Getting the ADT Plugin Sources

You can follow instructions from http://source.android.com/source/downloading.htm.

In total you should perform the following sequence of commands:
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl --insecure --proxy krsuls001:8080 https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
$ repo sync sdk

After this sdk project will be downloaded to your WORKING_DIRECTORY. You can list all available branches:

$ git branch –a

and also switch to version you need, for example ADT 15.0.1:

$ git checkout remotes/aosp/tools_r15


Notes:
android-2.3.7_r1 sources contain ADT 0.9.9 release
android-4.0.1_r1 sources contain ADT 14.0.0 release

Buiding the ADT Plugin from Android Source Tree under Linux

First of all you should get the whole Android Source Tree (see details at http://source.android.com/source/downloading.html).
Then you should get Eclipse RCP (http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR1/eclipse-rcp-indigo-SR1-linux-gtk.tar.gz)
Build Plugin:
  • WORKING_DIRECTORY – directory with Android Source Tree
  • eclipse_plugin – destination directory for plugin
$ cd WORKING_DIRECTORY
$ . build/envsetup.sh
$ lunch sdk-eng
$ export ECLIPSE_HOME=~/eclipse
$ ./sdk/eclipse/scripts/build_server.sh ~/eclipse_plugin/

In case of successful build you get the something like android-eclipse-v201111232103.zip in eclipse_plugin directory.

Building the ADT Plugin with Eclipse under Windows

First of all get the sdk source code necessary version. You will also need some libraries from android/prebuilt.
Then check that you have "Eclipse Plug-in Development Environment" installed in Eclipse.
In Eclipse right click in the Workspace and choose "Import...", then select "Existing Projects into Workspace". You need to import the following projects:
  • sdk\eclipse\plugins\com.android.ide.eclipse.adt
  • sdk\eclipse\plugins\com.android.ide.eclipse.ddms
  • sdk\eclipse\plugins\com.android.ide.eclipse.hierarchyviewer
  • sdk\eclipse\plugins\com.android.ide.eclipse.traceview
  • sdk\eclipse\plugins\com.android.ide.eclipse.adt.overlay
  • sdk\eclipse\features\com.android.ide.eclipse.adt
  • sdk\eclipse\features\com.android.ide.eclipse.ddms
  • sdk\eclipse\features\com.android.ide.eclipse.hierarchyviewer
  • sdk\eclipse\features\com.android.ide.eclipse.traceview
  • sdk\eclipse\sites\external
  • sdk\androidprefs
  • sdk\assetstudio
  • sdk\common
  • sdk\ddms (import all 3 projects - ddmlib, ddms-plugin, ddmuilib)
  • sdk\hierarchyviewer2 (import app, hierarchyviewerlib)
  • sdk\ide_common
  • sdk\layoutlib_api
  • sdk\rule_api
  • sdk\sdkmanager (import sdklib, sdkuilib)
  • sdk\sdkstats
  • sdk\swtmenubar
Define two User Libraries:
-    ANDROID_JFREECHART (add the 3 jars under android/prebuilt/common/jfreechart)
-    ANDROID_SWT (add the 3 jars under android/prebuilt/common/eclipse and android/prebuilt/windows/swt/swt.jar)
Some projects have ANDROID_SRC and ANDROID_OUT_FRAMEWORK Classpath Variables. Actually you could add requested jar files as “External JARs”.
To create *.jar file from sources:
-    Right click on Project
-    Select “Export”
-    Java -> JAR file, press Next
-    Select the export destination for JAR file

Note 1: You can face with the following error during modifying the project properties:

Remove the windows hidden attribute that is set on the .classpath file. This should fix the error.

Note 2: For adt-overlay project, to fix the error:
C:\workspace_tw\adt-overlay\build.xml:285: srcdir "C:\workspace_tw\adt-overlay\src" does not exist!
Just create empty folder adt-overlay/src.

Note 3: If there are compile errors such as:
The method addBooleanArg(String, boolean) of type RemoteAndroidTestRunner should be tagged with @Override since it actually overrides a superinterface method    RemoteAndroidTestRunner.java
check  the Project Properties -> Java Compiler -> Errors/Warnings settings.
You can disable project specific settings or just change setting for Annotations->”Missing @Override annotation” from error to warning.

Once you get rid of all compile errors you could either run/debug ADT in Eclipse or export plugin for installing with Eclipse Plugin Manager.

Run/debug ADT Plugin:

-    Just run adt project as "Eclipse Application"
-    Another copy of Eclipse will start were you can check you plugin functionality.

Export ADT Plugin:

-    Select external-site project
-    Open site.xml
-    Hit the “Build All” button

Add the following files and directories under external-site project directory to plugin.zip:

external-site\features\com.android.ide.eclipse.adt_15.0.1.201111231711.jar
external-site\features\com.android.ide.eclipse.ddms_15.0.1.201111231711.jar
external-site\features\com.android.ide.eclipse.hierarchyviewer_15.0.1.201111231711.jar
external-site\features\com.android.ide.eclipse.traceview_15.0.1.201111231711.jar
external-site\plugins\com.android.ide.eclipse.adt_15.0.1.201111231711.jar
external-site\plugins\com.android.ide.eclipse.ddms_15.0.1.201111231711.jar
external-site\plugins\com.android.ide.eclipse.hierarchyviewer_15.0.1.201111231711.jar
external-site\plugins\com.android.ide.eclipse.traceview_15.0.1.201111231711.jar
external-site\plugins\overlay.com.android.ide.eclipse.adt.overlay_15.0.1.201111231711.jar
external-site\web\site.css
external-site\web\site.xsl
external-site\index.html
external-site\site.xml


Now you can use plugin.zip as independent plugin.



1 comment:

  1. Hi Julia,
    great post.
    I am stumbling here years later still I am posting a related question here. Hopefully, it will catch your attention.

    I am trying to build a plugin which calls the default launcher of ADT plugin but not able to achieve it till now.
    I have the ADT source. So which the main class and method which gets called by eclipse with launch configuration ? And what would be the standard launch configuration for that.

    ReplyDelete