From 3aa6511539808303946698eb000b5bdfcca6111f Mon Sep 17 00:00:00 2001 From: Scott Main <> Date: Wed, 22 Apr 2009 13:24:58 -0700 Subject: AI 147313: am: CL 147311 update eclipse docs to include necessary AVD procedures and discuss relevant target facilities Original author: smain Merged from: //branches/cupcake/... Automated import of CL 147313 --- docs/html/guide/developing/eclipse-adt.jd | 500 +++++++++++++++++++++--------- 1 file changed, 350 insertions(+), 150 deletions(-) (limited to 'docs/html') diff --git a/docs/html/guide/developing/eclipse-adt.jd b/docs/html/guide/developing/eclipse-adt.jd index 8c482ee40ce5..4f332b13e8cb 100644 --- a/docs/html/guide/developing/eclipse-adt.jd +++ b/docs/html/guide/developing/eclipse-adt.jd @@ -1,193 +1,393 @@ -page.title=In Eclipse, with ADT +page.title=Developing In Eclipse, with ADT @jd:body -

The Android Development Tools (ADT) plugin for Eclipse adds powerful extensions to the Eclipse integrated development environment. It allows you to create and debug Android applications easier and faster. If you use Eclipse, the ADT plugin gives you an incredible boost in developing Android applications:

+
+
+

In this document

+
    +
  1. Creating an Android Project
  2. +
  3. Running Your Application +
      +
    1. Creating an AVD
    2. +
    3. Running an application
    4. +
    +
  4. +
  5. Creating a Custom Run Configuration
  6. +
  7. Setting Up Application Signing
  8. +
  9. Eclipse Tips
  10. +
+
+ + +

The Android Development Tools (ADT) plugin for Eclipse adds powerful extensions to the Eclipse +integrated development environment. It allows you to create and debug Android applications easier +and faster. If you use Eclipse, the ADT plugin gives you an incredible boost in developing Android +applications:

-

To begin developing Android applications in the Eclipse IDE with ADT, you first need to download the Eclipse IDE and then download and install the ADT plugin. To do so, follow the steps given in Installing the ADT Plugin, in the installation documentation included with your SDK package.

- -

Once you've installed the ADT plugin, you begin by creating an Android -project and then set up a launch configuration. After that, you can write, run, and debug -your application.

+

To begin developing Android applications in the Eclipse IDE with ADT, you first need to +download the Eclipse IDE and then download and install the ADT plugin. To do so, follow the +steps given in Installing +the ADT Plugin.

-

The sections below provide instructions assuming that you have installed the ADT plugin -in your Eclipse environment. If you haven't installed the ADT plugin, you should do that -before using the instructions below.

+

If you are already developing applications using a version of ADT earlier than 0.9, make +sure to upgrade to the latest version before continuing. See the guide to +Update Your Eclipse ADT Plugin.

- +

Note: This guide assumes you are using the latest version of +the ADT plugin (0.9). While most of the information covered also applies to previous +versions, if you are using an older version, you may want to consult this document from +the set of documentation included in your SDK package (instead of the online version).

-

Creating an Android Project

-

The ADT plugin provides a New Project Wizard that you can use to quickly create an -Eclipse project for new or existing code. To create the project, follow these steps:

+

Creating an Android Project

- +

The ADT plugin provides a New Project Wizard that you can use to quickly create a new +Android project (or a project from existing code). To create a new project:

    -
  1. Select File > New > Project
  2. -
  3. Select Android > Android Project, and press Next
  4. -
  5. Select the contents for the project: - -
  6. -
  7. Press Finish.
  8. -
- -

The ADT plugin creates the these folders and - files for you as appropriate for the type of project:

- +
  • Select File > New > Project.
  • +
  • Select Android > Android Project, and click + Next.
  • +
  • Select the contents for the project: + +
  • +
  • Click Finish.
  • - +

    Tip: +You can also start the New Project Wizard from the New icon in the toolbar.

    + +

    Once you complete the New Project Wizard, ADT creates the following +folders and files in your new project:

    +
    +
    src/
    +
    Includes your stub Activity Java file. All other Java files for your application + go here.
    +
    <Android Version>/ (e.g., Android 1.1/)
    +
    Includes the android.jar file that your application will build against. + This is determined by the build target that you have chosen in the New Project + Wizard.
    +
    gen/
    +
    This contains the Java files generated by ADT, such as your R.java file + and interfaces created from AIDL files.
    +
    assets/
    +
    This is empty. You can use it to store raw asset files. See + Resources and Assets.
    +
    res/
    +
    A folder for your application resources, such as drawable files, layout files, string + values, etc. See + Resources and Assets.
    +
    AndroidManifest.xml
    +
    The Android Manifest for your project. See + The AndroidManifest.xml + File.
    +
    default.properties
    +
    This file contains project settings, such as the build target. This files is integral + to the project, as such, it should be maintained in a Source Revision Control system. + It should never be edited manually — to edit project properties, + right-click the project folder and select "Properties".
    +
    + + +

    Running Your Application

    + +

    Wait! Before you can run your application on the Android Emulator, +you must create an Android Virtual Device (AVD). +An AVD is a configuration that specifies the Android platform to be used on the emulator. +You can read more about AVDs in the Developing +Overview, but if you just want to get started, follow the simple guide below to create +an AVD.

    + +

    If you will be running your applications only on actual device hardware, you do not +need an AVD — see +Developing On a Device for information +on running your applicaiton.

    + +

    Creating an AVD

    + +

    To avoid some explanation that's beyond the scope of this document, here's the +basic procedure to create an AVD:

    -

    Creating a Launch Configuration

    +
      +
    1. Open a command-line (e.g.,"Command Prompt" application on Windows, or "Terminal" + on Mac/Linux) and navigate to your SDK package's + tools/ directory.
    2. +
    3. First, you need to select a Deployment Target. To view available targets, execute: +
      android list targets
      +

      This will output a list of available Android targets, such as:

      +
      +id:1
      +    Name: Android 1.1
      +    Type: platform
      +    API level: 2
      +    Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
      +id:2
      +    Name: Android 1.5
      +    Type: platform
      +    API level: 3
      +    Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
      +
      +

      Find the target that matches the Android platform upon which you'd like + to run your application. Note the integer value of the id — + you'll use this in the next step.

      +
    4. +
    5. Create a new AVD using your selected Deployment Target. Execute: +
      android create avd --name <your_avd_name> --target <targetID>
      +
    6. Next, you'll be asked whether you'd like to create a custom hardware profile. + If you respond "yes," you'll be presented with a series of prompts to define various aspects of the + device hardware (leave entries blank to use default values, which are shown in brackets). Otherwise, + press return to use all default values ("no" is the default).
    7. + +
    -

    Before you can run and debug your application in Eclipse, you must create a launch configuration for it. A launch configuration specifies the project to launch, the Activity to start, the emulator options to use, and so on.

    +

    That's it; your AVD is ready. In the next section, you'll see how the AVD is used +when launching your application on an emulator.

    -

    To create a launch configuration for the application, follow these steps as appropriate for your Eclipse version:

    +

    To learn more about creating and managing AVDs, please read the +Developing Overview +and android Tool documentation.

    -
      -
    1. Open the launch configuration manager. - -
    2. -
    3. In the project type list on the left, locate the Android Application item and double-click it (or right-click > New), to create a new launch configuration.
    4. -
    5. Enter a name for your configuration.
    6. -
    7. On the Android tab, browse for the project and Activity to start.
    8. -
    9. On the Target tab, set the desired screen and network properties, as well as any other emulator startup options.
    10. -
    11. You can set additional options on the Common tab as desired.
    12. -
    13. Press Apply to save the launch configuration, or press Run or Debug (as appropriate).
    14. +

      Running your application

      -
    +

    Note: Before you can run your application, be sure that +you have created an AVD with a target that satisfies your application's Build Target. +If an AVD cannot be found that meets the requirements of your Build Target, you will see +a console error telling you so and the launch will be aborted.

    +

    To run (or debug) your application, select Run > Run (or +Run > Debug) from the Eclipse main menu. The ADT plugin +will automatically create a default launch configuration for the project.

    -

    Setting Up Application Signing

    +

    When you choose to run or debug your application, Eclipse will perform the following:

    -

    As you begin developing Android applications, you should understand that all -Android applications must be digitally signed before the system will install -them on the emulator or an actual device.

    +
      +
    1. Compile the project (if there have been changes since the last build).
    2. +
    3. Create a default launch configuration (if one does not already exist for the project).
    4. +
    5. Install and start the application on an emulator or device (based on the Deployment Target + defined by the run configuration). +

      By default, Android application run configurations use an "automatic target" mode for + selecting a device target. For information on how automatic target mode selects a + deployment target, see Automatic and manual + target modes below.

      +
    6. +
    -

    The ADT plugin helps you get started quickly by signing your .apk files with -a debug key, prior to installing them on the emulator. This means that you can -compile your application and install it on the emulator without having to -generate your own private key. However, please note that if you intend to -publish your application, you must sign the application with your own -private key, rather than the debug key generated by the SDK tools.

    +

    If debugging, the application will start in the "Waiting For Debugger" mode. Once the +debugger is attached, Eclipse will open the Debug perspective.

    + +

    To set or change the launch configuration used for your project, use the launch configuration manager. +See Creating a Launch Configuration for information.

    -

    To sign your applications, the ADT plugin requires the Keytool utility -included in the JDK. To set up your development environment for -signing, you need to make sure that Keytool is available on your -machine that the ADT plugin knows how to find it.

    -

    In most cases, you can tell the SDK build tools how to find Keytool by making -sure that your JAVA_HOME environment variable is set and that it references a -suitable JDK. Alternatively, you can add the JDK version of Keytool to your -PATH variable.

    +

    Creating a Run Configuration

    -

    If you are developing on a version of Linux that originally came with Gnu -Compiler for Java, make sure that the system is using the JDK version of -Keytool, rather than the gcj version. If keytool is already in your PATH, it -might be pointing to a symlink at /usr/bin/keytool. In this case, check the -symlink target to make sure that it points to the keytool in the JDK.

    +

    The run configuration specifies the project to run, the Activity +to start, the emulator options to use, and so on. When you first run a project +as an Android Application, ADT will automatically create a run configuration. +The default run configuration will +launch the default project Activity and use automatic target mode for device selection +(with no preferred AVD). If the default setting don't suit your project, you can +customize the launch configuration or even create a new.

    -

    In all cases, please read and understand Signing Your -Applications, which provides an overview of application signing on Android -and what it means to you as an Android application developer.

    +

    To create or modify a launch configuration, follow these steps as appropriate +for your Eclipse version:

    +
      +
    1. Open the run configuration manager. + +
    2. +
    3. Expand the Android Application item and create a new + configuration or open an existing one. + +
    4. +
    5. Adjust your desired launch configuration settings. +

      In the Target tab, consider whether you'd like to use Manual or Automatic mode + when selecting an AVD to run your application. + See the following section on Automatic and manual target + modes).

      +
    6. +
    - -

    Running and Debugging an Application

    +

    Automatic and manual target modes

    -

    Once you've set up the project and launch configuration for your application, you can run or debug it as described below.

    +

    By default, a run configuration uses the automatic target mode in order to select +an AVD. In this mode, ADT will select an AVD for the application in the following manner:

    -From the Eclipse main menu, select Run > Run or Run > Debug as appropriate, to run or debug the active launch configuration. +
      +
    1. If there's a device or emulator already running and its AVD configuration + meets the requirements of the application's build target, the application is installed + and run upon it.
    2. +
    3. If there's more than one device or emulator running, each of which meets the requirements + of the build target, a "device chooser" is shown to let you select which device to use.
    4. +
    5. If there are no devices or emulators running that meet the requirements of the build target, + ADT looks at the available AVDs. If one meets the requirements of the build target, + the AVD is used to launch a new emulator, upon which the application is installed and run.
    6. +
    7. If all else fails, the application will not be run and you will see a console error warning + you that there is no existing AVD that meets the build target requirements.
    8. +
    -

    Note that the active launch configuration is the one most recently selected in the Run configuration manager. It does not necessarily correspond to the application that is selected in the Eclipse Navigation pane (if any).

    +

    However, if a "preferred AVD" is selected in the run configuration, then the application +will always be deployed to that AVD. If it's not already running, then a new emulator +will be launched.

    -

    To set or change the active launch configuration, use the launch configuration manager. See Creating a Launch Configuration for information about how to access the launch configuration manager..

    +

    If your run configuration uses manual mode, then the "device chooser" +is presented every time that your application is run, so that you can select which AVD to use.

    -

    Running or debugging the application triggers these actions:

    - +

    Signing your Applications

    +

    As you begin developing Android applications, understand that all +Android applications must be digitally signed before the system will install +them on an emulator or an actual device. There are two ways to do this: +with a debug key (for immediate testing on an emulator or development device) +or with a private key (for application distribution).

    -

    Eclipse Tips

    -

    Executing arbitrary Java expressions in Eclipse

    -

    You can execute arbitrary code when paused at a breakpoint in Eclipse. For example, - when in a function with a String argument called "zip", you can get - information about packages and call class methods. You can also invoke arbitrary - static methods: for example, entering android.os.Debug.startMethodTracing() will - start dmTrace.

    -

    Open a code execution window, select Window>Show - View>Display from the main menu to open the - Display window, a simple text editor. Type your expression, highlight the - text, and click the 'J' icon (or CTRL + SHIFT + D) to run your - code. The code runs in the context of the selected thread, which must be - stopped at a breakpoint or single-step point. (If you suspend the thread - manually, you have to single-step once; this doesn't work if the thread is - in Object.wait().)

    -

    If you are currently paused on a breakpoint, you can simply highlight and execute - a piece of source code by pressing CTRL + SHIFT + D.

    -

    You can highlight a block of text within the same scope by pressing ALT +SHIFT - + UP ARROW to select larger and larger enclosing blocks, or DOWN ARROW to select - smaller blocks.

    -

    Here are a few sample inputs and responses in Eclipse using the Display window.

    - - - - - - - - - - - - - - - - - -
    InputResponse
    zip(java.lang.String) /work/device/out/linux-x86-debug/android/app/android_sdk.zip
    zip.endsWith(".zip")(boolean) true
    zip.endsWith(".jar")(boolean) false
    -

    You can also execute arbitrary code when not debugging by using a scrapbook page. - Search the Eclipse documentation for "scrapbook".

    - -

    Running DDMS Manually

    - -

    Although the recommended way to debug is to use the ADT plugin, you can manually run DDMS and configure Eclipse to debug on port 8700. (Note: Be sure that you have first started DDMS).

    +

    The ADT plugin helps you get started quickly by signing your .apk files with +a debug key, prior to installing them on an emulator or development device. This means that you can +quickly run your application from Eclipse without having to +generate your own private key. No specific action on your part is needed, +provided ADT has access to Keytool.However, please note that if you intend +to publish your application, you must sign the application with your +own private key, rather than the debug key generated by the SDK tools.

    + +

    Please read Signing Your +Applications, which provides a thorough guide to application signing on Android +and what it means to you as an Android application developer. The document also includes +a guide to exporting and signing your application with the ADT's Export Wizard.

    + + +

    Eclipse Tips

    + +

    Executing arbitrary Java expressions in Eclipse

    + +

    You can execute arbitrary code when paused at a breakpoint in Eclipse. For example, + when in a function with a String argument called "zip", you can get + information about packages and call class methods. You can also invoke arbitrary + static methods: for example, entering android.os.Debug.startMethodTracing() will + start dmTrace.

    +

    Open a code execution window, select Window>Show + View>Display from the main menu to open the + Display window, a simple text editor. Type your expression, highlight the + text, and click the 'J' icon (or CTRL + SHIFT + D) to run your + code. The code runs in the context of the selected thread, which must be + stopped at a breakpoint or single-step point. (If you suspend the thread + manually, you have to single-step once; this doesn't work if the thread is + in Object.wait().)

    +

    If you are currently paused on a breakpoint, you can simply highlight and execute + a piece of source code by pressing CTRL + SHIFT + D.

    +

    You can highlight a block of text within the same scope by pressing ALT +SHIFT + + UP ARROW to select larger and larger enclosing blocks, or DOWN ARROW to select + smaller blocks.

    +

    Here are a few sample inputs and responses in Eclipse using the Display window.

    + + + + + + + + + + + + + + + + + + +
    InputResponse
    zip(java.lang.String) + /work/device/out/linux-x86-debug/android/app/android_sdk.zip
    zip.endsWith(".zip")(boolean) true
    zip.endsWith(".jar")(boolean) false
    +

    You can also execute arbitrary code when not debugging by using a scrapbook page. + Search the Eclipse documentation for "scrapbook".

    + + +

    Running DDMS Manually

    + +

    Although the recommended way to debug is to use the ADT plugin, you can manually run +DDMS and configure Eclipse to debug on port 8700. (Note: Be sure that you +have first started DDMS).

    + + + -- cgit v1.2.3-59-g8ed1b