Set up Eclipse

Follow these steps to set up Tradefed using Eclipse.

Create a separate workspace to develop Trade Federation, do not reuse a workspace already employed for Android-device development.

If needed, you can download the Eclipse IDE for Java developers from:

Create projects

  1. Run make once from the command line. This will build external libraries depended by the projects below.
  2. Set TRADEFED_ROOT classpath variable in Window > Preferences > Java > Build Path> Classpath Variables and point it to your tradefed source root
  3. Set TRADEFED_ROOT path variable in Window > Preferences > General > Workspace > Linked Resources and point it to your tradefed source root
  4. Use the File > Import...-> General > Existing Projects into workspace"wizard to bring in these open source Java projects under the following paths:

  5. Optionally, if you want to see ddmlib source code, attach the source code from an unbundled tools branch, such as /platform/tools/base/tools_r22/ddmlib/src/main/java/com/android/ddmlib/

  6. Optionally, if you also want the CTS harness projects loaded, import:


Auto format

NOTE: Requisite files live within development/ide/eclipse in the full platform source tree. So you will need to check out a platform branch such as main to get these files: /development/main/ide/eclipse/

Use preference files in Eclipse to automatically set the formatter to the Android style guide. To do this in Studio:

  1. Go to Window > Preferences > Java > Code Style.
  2. Under Formatter, import the file android-formatting.xml.
  3. Under Organize > Imports, import the file android.importorder.

Remove trailing whitespaces

To force Eclipse to remove all trailing whitespace:

  1. Go to Window > Preferences -> Java -> Editor -> Save Actions.
  2. Then Additional Actions -> Configure -> Code > Organizing tab -> Formatter.
  3. Check Remove Trailing Whitespace.
  4. Click Apply and Close.

Check code style

When submitting a changelist, an automatic preupload hook will run to check your code format: google-java-format

This helps formatting your code to the common standard.

Debug Eclipse

If you want to run TF code through a debugger in Eclipse, it is recommended you first create a unit test for the code in question as this will be the simplest and fastest way to exercise the functionalilty.

To debug a TF unit test, simply right-click on it and select Debug As > JUnit test.

To debug a TF functional test, follow the instructions in the previous section for running a functional test but use the Run > Debug configurations menu.

To debug the TF program itself, when running any configuration, follow the instructions in the previous section for running a functional test but provide the command line arguments for the configuration you wish to run in step 4. So to debug the 'instrument' configuration, go to the Run > Debug configuration menu and set the Arguments tab in the Eclipse debug configuration to -- package <package to run> instrument.

Remote debug with Eclipse

Follow these steps to remotely debug a tradefed session started from command line:

  1. Start with the debug flag: TF_DEBUG=1
  2. Wait until you see this prompt from the JVM: Listening for transport dt_socket at address: 10088 This means the JVM is waiting for debugger to attach at port 10088.
  3. Attach with Eclipse's remote debugging from main menu: Select Run > Debug Configurations....
  4. In the pop-up dialog, select Remote Java Application from the left menu.
  5. Click the New launch configuration icon on the action bar.
  6. Name the configuration as you desire and select tradefederation as the project.
  7. Populate the port using the address provided earlier.
  8. Switch to the Source tab and add the projects tradefederation and google-tradefed to the Source Lookup Path.
  9. Click Debug to start the debugging session.

The debugger attaches to the listening JVM process, and the terminal running shows the tf> prompt.

To step through your code in debug mode, set a break point in Eclipse and invoke your Tradefed command (i.e. run <test>) in the terminal. To debug anything during TF startup, you can set the break point first and then attach the Eclipse debugger.

TIP: To use an alternative port, add TF_DEBUG_PORT=nnnto the command in step 1 above. You can even use this in production environment if you have mysterious hang bugs to investigate: change suspend=y to suspend=n in and start with debug flag. The JVM won't wait for debugger to attach, but you can do so at any time as long as the process is still running.

Remote debug using JDB

To use the Java Debugger JDB, follow steps resembling those for Eclipse:

  1. Start with the debug flag: TF_DEBUG=1
  2. Wait until you see the prompt from JVM: Listening for transport dt_socket at address: 10088.
  3. Connect jdb. For example, from croot run:

    jdb -attach 10088 \
        -sourcepath tools/tradefederation/core/src:vendor/google_tradefederation/core/src
  4. Wait for the connection and debug away! Run man jdb for more help.

Examine code coverage

  1. Install the Eclemma plugin.
  2. Go to Help > Install New Software and point the wizard to:
  3. Once installed, select the Coverage As > JUnit test option to conduct a code coverage run.