| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 1 | page.title=Developing In Eclipse, with ADT |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | @jd:body |
| 3 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 4 | <div id="qv-wrapper"> |
| 5 | <div id="qv"> |
| 6 | <h2>In this document</h2> |
| 7 | <ol> |
| 8 | <li><a href="#CreatingAProject">Creating an Android Project</a></li> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 9 | <li><a href="#AVD">Creating an AVD</a></li> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 10 | <li><a href="#Running">Running Your Application</a> |
| 11 | <ol> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 12 | <li><a href="#RunningOnEmulator">Running on the emulator</a></li> |
| 13 | <li><a href="#RunningOnDevice">Running on a device</a></li> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 14 | </ol> |
| 15 | </li> |
| 16 | <li><a href="#RunConfig">Creating a Custom Run Configuration</a></li> |
| 17 | <li><a href="#Signing">Setting Up Application Signing</a></li> |
| 18 | <li><a href="#Tips">Eclipse Tips</a></li> |
| 19 | </div> |
| 20 | </div> |
| 21 | |
| 22 | |
| 23 | <p>The Android Development Tools (ADT) plugin for Eclipse adds powerful extensions to the Eclipse |
| 24 | integrated development environment. It allows you to create and debug Android applications easier |
| 25 | and faster. If you use Eclipse, the ADT plugin gives you an incredible boost in developing Android |
| 26 | applications:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | <ul> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 29 | <li>It gives you access to other Android development tools from inside the Eclipse IDE. For |
| 30 | example, ADT lets you access the many capabilities of the DDMS tool: take screenshots, manage |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 31 | port-forwarding, set breakpoints, and view thread and process information directly from |
| 32 | Eclipse.</li> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 33 | <li>It provides a New Project Wizard, which helps you quickly create and set up all of the |
| 34 | basic files you'll need for a new Android application.</li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | <li>It automates and simplifies the process of building your Android application.</li> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 36 | <li>It provides an Android code editor that helps you write valid XML for your Android |
| 37 | manifest and resource files.</li> |
| 38 | <li>It will even export your project into a signed APK, which can be distributed to users.</li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | </ul> |
| 40 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 41 | <p>To begin developing Android applications in the Eclipse IDE with ADT, you first need to |
| 42 | download the Eclipse IDE and then download and install the ADT plugin. To do so, follow the |
| Dirk Dougherty | ee58d1b | 2009-10-16 15:25:15 -0700 | [diff] [blame] | 43 | steps given in <a href="{@docRoot}sdk/eclipse-adt.html#installing">Installing |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 44 | the ADT Plugin</a>.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 46 | <p>If you are already developing applications using a version of ADT earlier than 0.9, make |
| 47 | sure to upgrade to the latest version before continuing. See the guide to |
| Dirk Dougherty | ee58d1b | 2009-10-16 15:25:15 -0700 | [diff] [blame] | 48 | <a href="{@docRoot}sdk/eclipse-adt.html#updating">Updating Your ADT Plugin</a>.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 50 | <p class="note"><strong>Note:</strong> This guide assumes you are using the latest version of |
| Dirk Dougherty | 3f9de8b | 2009-05-22 16:04:18 -0700 | [diff] [blame] | 51 | the ADT plugin. While most of the information covered also applies to previous |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 52 | versions, if you are using an older version, you may want to consult this document from |
| 53 | the set of documentation included in your SDK package (instead of the online version).</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 56 | <h2 id="CreatingAProject">Creating an Android Project</h2> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 58 | <p>The ADT plugin provides a New Project Wizard that you can use to quickly create a new |
| 59 | Android project (or a project from existing code). To create a new project:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
| 61 | <ol> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 62 | <li>Select <strong>File</strong> > <strong>New</strong> > <strong>Project</strong>.</li> |
| 63 | <li>Select <strong>Android</strong> > <strong>Android Project</strong>, and click |
| 64 | <strong>Next</strong>.</li> |
| 65 | <li>Select the contents for the project: |
| 66 | <ul> |
| 67 | <li>Enter a <em>Project Name</em>. This will be the name of the folder where your |
| 68 | project is created.</li> |
| 69 | <li>Under Contents, select <strong>Create new project in workspace</strong>. |
| 70 | Select your project workspace location.</li> |
| 71 | <li>Under Target, select an Android target to be used as the project's Build Target. |
| 72 | The Build Target |
| 73 | specifies which Android platform you'd like your application built against. |
| 74 | <p>Unless you know that you'll be using new APIs introduced in the latest SDK, you should |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 75 | select a target with the lowest platform version possible.</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 76 | <p class="note"><strong>Note:</strong> You can change your the Build Target for your |
| 77 | project at any time: Right-click the project in the Package Explorer, select |
| 78 | <strong>Properties</strong>, select <strong>Android</strong> and then check |
| 79 | the desired Project Target.</p> |
| 80 | </li> |
| 81 | <li>Under Properties, fill in all necessary fields. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | <ul> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 83 | <li>Enter an <em>Application name</em>. This is the human-readable title for your |
| 84 | application — the name that will appear on the Android device.</li> |
| 85 | <li>Enter a <em>Package name</em>. This is the package namespace (following the same rules |
| 86 | as for packages in the Java programming language) where all your source code |
| 87 | will reside.</li> |
| 88 | <li>Select <em>Create Activity</em> (optional, of course, but common) and enter a name |
| 89 | for your main Activity class.</li> |
| 90 | <li>Enter a <em>Min SDK Version</em>. This is an integer that indicates |
| 91 | the minimum API Level required to properly run your application. |
| 92 | Entering this here automatically sets the <code>minSdkVersion</code> attribute in the |
| 93 | <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><uses-sdk></a> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 94 | of your Android Manifest file. If you're unsure of the appropriate <a |
| 95 | href="{@docRoot}guide/appendix/api-levels.html">API Level</a> to use, |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 96 | copy the API Level listed for the Build Target you selected in the Target tab.</li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | </ul> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 98 | </li> |
| 99 | </ul> |
| 100 | </li> |
| 101 | <li>Click <strong>Finish</strong>.</li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | </ol> |
| 103 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 104 | <p class="note"><strong>Tip:</strong> |
| 105 | You can also start the New Project Wizard from the <em>New</em> icon in the toolbar.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 107 | <p>Once you complete the New Project Wizard, ADT creates the following |
| 108 | folders and files in your new project:</p> |
| 109 | <dl> |
| 110 | <dt><code>src/</code></dt> |
| 111 | <dd>Includes your stub Activity Java file. All other Java files for your application |
| 112 | go here.</dd> |
| 113 | <dt><code><em><Android Version></em>/</code> (e.g., <code>Android 1.1/</code>)</dt> |
| 114 | <dd>Includes the <code>android.jar</code> file that your application will build against. |
| 115 | This is determined by the build target that you have chosen in the <em>New Project |
| 116 | Wizard</em>.</dd> |
| 117 | <dt><code>gen/</code></dt> |
| 118 | <dd>This contains the Java files generated by ADT, such as your <code>R.java</code> file |
| 119 | and interfaces created from AIDL files.</dd> |
| 120 | <dt><code>assets/</code></dt> |
| 121 | <dd>This is empty. You can use it to store raw asset files. See |
| 122 | <a href="{@docRoot}guide/topics/resources/index.html">Resources and Assets</a>.</dd> |
| 123 | <dt><code>res/</code></dt> |
| 124 | <dd>A folder for your application resources, such as drawable files, layout files, string |
| 125 | values, etc. See |
| 126 | <a href="{@docRoot}guide/topics/resources/index.html">Resources and Assets</a>.</dd> |
| 127 | <dt><code>AndroidManifest.xml</code></dt> |
| 128 | <dd>The Android Manifest for your project. See |
| 129 | <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml |
| 130 | File</a>.</dd> |
| 131 | <dt><code>default.properties</code></dt> |
| 132 | <dd>This file contains project settings, such as the build target. This files is integral |
| 133 | to the project, as such, it should be maintained in a Source Revision Control system. |
| 134 | It should never be edited manually — to edit project properties, |
| 135 | right-click the project folder and select "Properties".</dd> |
| 136 | </dl> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 139 | <h2 id="AVD">Creating an AVD</h2> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 140 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 141 | <p>An Android Virtual Device (AVD) is a device configuration for the emulator that |
| 142 | allows you to model real world devices. In order to run an instance of the emulator, you must create |
| 143 | an AVD.</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 144 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 145 | <p>To create an AVD from Eclipse:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | |
| 147 | <ol> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 148 | <li>Select <strong>Window > Android SDK and AVD Manager</strong>, or click the Android SDK and |
| 149 | AVD Manager icon in the Eclipse toolbar.</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 150 | </li> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 151 | <li>In the <em>Virtual Devices</em> panel, you'll see a list of existing AVDs. Click |
| 152 | <strong>New</strong> to create a new AVD.</li> |
| 153 | <li>Fill in the details for the AVD. |
| 154 | <p>Give it a name, a platform target, an SD card size, and |
| Scott Main | 75f7a26 | 2009-08-05 19:31:00 -0700 | [diff] [blame] | 155 | a skin (HVGA is default).</p> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 156 | <p class="note"><strong>Note:</strong> Be sure to define |
| 157 | a target for your AVD that satisfies your application's Build Target (the AVD |
| 158 | platform target must have an API Level equal to or greater than the API Level that your |
| 159 | application compiles against).</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 160 | </li> |
| Scott Main | 75f7a26 | 2009-08-05 19:31:00 -0700 | [diff] [blame] | 161 | <li>Click <strong>Create AVD</strong>.</li> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 162 | </ol> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 164 | <p>Your AVD is now ready and you can either close the SDK and AVD Manager, create more AVDs, or |
| 165 | launch an emulator with the AVD by selecting a device and clicking <strong>Start</strong>.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 167 | <p>For more information about AVDs, read the |
| Scott Main | 8a4c53a | 2009-04-24 13:41:44 -0700 | [diff] [blame] | 168 | <a href="{@docRoot}guide/developing/tools/avd.html">Android Virtual Devices</a> |
| 169 | documentation.</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 170 | |
| 171 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 172 | <h2 id="Running">Running Your Application</h2> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 173 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 174 | <div class="sidebox-wrapper"> |
| 175 | <div class="sidebox"> |
| 176 | <h2>Use the Emulator to Test Different Configurations</h2> |
| 177 | <p>Create multiple AVDs that each define a different device configuration with which your |
| 178 | application is compatible, then launch each AVD into a new emulator from the SDK and AVD Manager. |
| 179 | Set the target mode in your app's run configuration to manual, so that when you run your |
| 180 | application, you can select from the available virtual devices.</p> |
| 181 | </div> |
| 182 | </div> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 183 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 184 | <p>Running your application from Eclipse will usually require just a couple clicks, whether you're |
| 185 | running it on the emulator or on an attached device. The information below describes how to get |
| 186 | set up and run your application from Eclipse.</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 187 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 188 | <h3 id="RunningOnEmulator">Running on the emulator</h3> |
| 189 | |
| 190 | <p>Before you can run your application on the Android Emulator, |
| 191 | you <strong>must</strong> <a href="#AVD">create an AVD</a>.</p> |
| 192 | |
| 193 | <p>To run (or debug) your application, select <strong>Run</strong> > <strong>Run</strong> (or |
| 194 | <strong>Run</strong> > <strong>Debug</strong>) from the Eclipse menu bar. The ADT plugin |
| 195 | will automatically create a default launch configuration for the project. Eclipse will then perform |
| 196 | the following:</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 197 | |
| 198 | <ol> |
| 199 | <li>Compile the project (if there have been changes since the last build).</li> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 200 | <li>Create a default launch configuration (if one does not already exist for the |
| 201 | project).</li> |
| 202 | <li>Install and start the application on an emulator (or device), based on the Deployment |
| 203 | Target |
| 204 | defined by the run configuration. |
| 205 | <p>By default, Android run configurations use an "automatic target" mode for |
| 206 | selecting a device target. For information on how automatic target mode selects a |
| 207 | deployment target, see <a href="#AutoAndManualTargetModes">Automatic and manual |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 208 | target modes</a> below.</p> |
| 209 | </li> |
| 210 | </ol> |
| 211 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 212 | <p>If debugging, the application will start in the "Waiting For Debugger" mode. Once the |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 213 | debugger is attached, Eclipse will open the Debug perspective.</p> |
| 214 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 215 | <p>To set or change the launch configuration used for your project, use the launch configuration |
| 216 | manager. |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 217 | See <a href="#launchconfig">Creating a Launch Configuration</a> for information.</p> |
| 218 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 219 | <p>Be certain to create multiple AVDs upon which to test your application. You should have one AVD |
| 220 | for each platform and screen type with which your application is compatible. For |
| 221 | instance, if your application compiles against the Android 1.5 (API Level 3) platform, you should |
| 222 | create an AVD for each platform equal to and greater than 1.5 and an AVD for each <a |
| 223 | href="{@docRoot}guide/practices/screens_support.html">screen type</a> you support, then test |
| 224 | your application on each one.</p> |
| 225 | |
| 226 | |
| 227 | <h3 id="RunningOnDevice">Running on a device</h3> |
| 228 | |
| 229 | <p>Before you can run your application on a device, you must perform some basic setup for your |
| 230 | device:</p> |
| 231 | |
| 232 | <ul> |
| 233 | <li>Declare your application as debuggable in your manifest</li> |
| 234 | <li>Enable USB Debugging on your device</li> |
| 235 | <li>Ensure that your development computer can detect your device when connected via USB</li> |
| 236 | </ul> |
| 237 | <p>Read <a href="{@docRoot}guide/developing/device.html#setting-up">Setting up a Device for |
| 238 | Development</a> for more information.</p> |
| 239 | |
| 240 | <p>Once set up and your device is connected via USB, install your application on the device by |
| 241 | selecting <strong>Run</strong> > <strong>Run</strong> (or |
| 242 | <strong>Run</strong> > <strong>Debug</strong>) from the Eclipse menu bar.</p> |
| 243 | |
| 244 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 245 | |
| 246 | <h2 id="RunConfig">Creating a Run Configuration</h2> |
| 247 | |
| 248 | <p>The run configuration specifies the project to run, the Activity |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 249 | to start, the emulator or connected device to use, and so on. When you first run a project |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 250 | as an <em>Android Application</em>, ADT will automatically create a run configuration. |
| 251 | The default run configuration will |
| 252 | launch the default project Activity and use automatic target mode for device selection |
| Dirk Dougherty | a6602f1 | 2009-08-27 16:26:43 -0700 | [diff] [blame] | 253 | (with no preferred AVD). If the default settings don't suit your project, you can |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 254 | customize the launch configuration or even create a new.</p> |
| 255 | |
| 256 | <p>To create or modify a launch configuration, follow these steps as appropriate |
| 257 | for your Eclipse version:</p> |
| 258 | |
| 259 | <ol> |
| 260 | <li>Open the run configuration manager. |
| 261 | <ul> |
| 262 | <li>In Eclipse 3.3 (Europa), select <strong>Run</strong> > |
| 263 | <strong>Open Run Dialog</strong> (or <strong>Open Debug Dialog</strong>) |
| 264 | </li> |
| 265 | <li>In Eclipse 3.4 (Ganymede), select <strong>Run </strong>> |
| 266 | <strong>Run Configurations</strong> (or |
| 267 | <strong>Debug Configurations</strong>) |
| 268 | </li> |
| 269 | </ul> |
| 270 | </li> |
| 271 | <li>Expand the <strong>Android Application</strong> item and create a new |
| 272 | configuration or open an existing one. |
| 273 | <ul> |
| 274 | <li>To create a new configuration: |
| 275 | <ol> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 276 | <li>Select <strong>Android Application</strong> and click the <em>New launch |
| 277 | configuration</em> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 278 | icon above the list (or, right-click <strong>Android Application</strong> and click |
| 279 | <strong>New</strong>).</li> |
| 280 | <li>Enter a Name for your configuration.</li> |
| 281 | <li>In the Android tab, browse and select the project you'd like to run with the |
| 282 | configuration.</li> |
| 283 | </ol> |
| 284 | <li>To open an existing configuration, select the configuration name from the list |
| 285 | nested below <strong>Android Application</strong>.</li> |
| 286 | </ul> |
| 287 | </li> |
| 288 | <li>Adjust your desired launch configuration settings. |
| 289 | <p>In the Target tab, consider whether you'd like to use Manual or Automatic mode |
| 290 | when selecting an AVD to run your application. |
| 291 | See the following section on <a href=#AutoAndManualModes">Automatic and manual target |
| 292 | modes</a>).</p> |
| Dirk Dougherty | a6602f1 | 2009-08-27 16:26:43 -0700 | [diff] [blame] | 293 | <p>You can specify any emulator options to the Additional Emulator Command |
| 294 | Line Options field. For example, you could add <code>-scale 96dpi</code> to |
| 295 | scale the AVD's screen to an accurate size, based on the dpi of your |
| 296 | computer monitor. For a full list of emulator options, see the <a |
| 297 | href="{@docRoot}guide/developing/tools/emulator.html">Android Emulator</a> |
| 298 | document.</p> |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 299 | </li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | </ol> |
| 301 | |
| 302 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 303 | <h3 id="AutoAndManualTargetModes">Automatic and manual target modes</h3> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 305 | <p>By default, a run configuration uses the <strong>automatic</strong> target mode in order to |
| 306 | select |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 307 | an AVD. In this mode, ADT will select an AVD for the application in the following manner:</p> |
| 308 | |
| 309 | <ol> |
| 310 | <li>If there's a device or emulator already running and its AVD configuration |
| 311 | meets the requirements of the application's build target, the application is installed |
| 312 | and run upon it.</li> |
| 313 | <li>If there's more than one device or emulator running, each of which meets the requirements |
| 314 | of the build target, a "device chooser" is shown to let you select which device to use.</li> |
| 315 | <li>If there are no devices or emulators running that meet the requirements of the build target, |
| 316 | ADT looks at the available AVDs. If one meets the requirements of the build target, |
| 317 | the AVD is used to launch a new emulator, upon which the application is installed and run.</li> |
| 318 | <li>If all else fails, the application will not be run and you will see a console error warning |
| 319 | you that there is no existing AVD that meets the build target requirements.</li> |
| 320 | </ol> |
| 321 | |
| 322 | <p>However, if a "preferred AVD" is selected in the run configuration, then the application |
| 323 | will <em>always</em> be deployed to that AVD. If it's not already running, then a new emulator |
| 324 | will be launched.</p> |
| 325 | |
| 326 | <p>If your run configuration uses <strong>manual</strong> mode, then the "device chooser" |
| 327 | is presented every time that your application is run, so that you can select which AVD to use.</p> |
| 328 | |
| 329 | |
| 330 | <h2 id="Signing">Signing your Applications</h2> |
| 331 | |
| 332 | <p>As you begin developing Android applications, understand that all |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | Android applications must be digitally signed before the system will install |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 334 | them on an emulator or an actual device. There are two ways to do this: |
| 335 | with a debug key (for immediate testing on an emulator or development device) |
| 336 | or with a private key (for application distribution).</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | |
| 338 | <p>The ADT plugin helps you get started quickly by signing your .apk files with |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 339 | a debug key, prior to installing them on an emulator or development device. This means that you can |
| 340 | quickly run your application from Eclipse without having to |
| 341 | generate your own private key. No specific action on your part is needed, |
| 342 | provided ADT has access to Keytool.However, please note that if you intend |
| 343 | to publish your application, you <strong>must</strong> sign the application with your |
| 344 | own private key, rather than the debug key generated by the SDK tools.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 346 | <p>Please read <a href="{@docRoot}guide/publishing/app-signing.html">Signing Your |
| 347 | Applications</a>, which provides a thorough guide to application signing on Android |
| 348 | and what it means to you as an Android application developer. The document also includes |
| 349 | a guide to exporting and signing your application with the ADT's Export Wizard.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | |
| 351 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 352 | <h2 id="Tips">Eclipse Tips </h2> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 354 | <h3 id="arbitraryexpressions">Executing arbitrary Java expressions in Eclipse</h3> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 356 | <p>You can execute arbitrary code when paused at a breakpoint in Eclipse. For example, |
| 357 | when in a function with a String argument called "zip", you can get |
| 358 | information about packages and call class methods. You can also invoke arbitrary |
| 359 | static methods: for example, entering <code>android.os.Debug.startMethodTracing()</code> will |
| 360 | start dmTrace. </p> |
| Scott Main | 0197999 | 2010-04-05 17:42:17 -0700 | [diff] [blame^] | 361 | <p>Open a code execution window, select <strong>Window</strong> > <strong>Show |
| 362 | View</strong> > <strong>Display</strong> from the main menu to open the |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 363 | Display window, a simple text editor. Type your expression, highlight the |
| 364 | text, and click the 'J' icon (or CTRL + SHIFT + D) to run your |
| 365 | code. The code runs in the context of the selected thread, which must be |
| 366 | stopped at a breakpoint or single-step point. (If you suspend the thread |
| 367 | manually, you have to single-step once; this doesn't work if the thread is |
| 368 | in Object.wait().)</p> |
| 369 | <p>If you are currently paused on a breakpoint, you can simply highlight and execute |
| 370 | a piece of source code by pressing CTRL + SHIFT + D. </p> |
| 371 | <p>You can highlight a block of text within the same scope by pressing ALT +SHIFT |
| 372 | + UP ARROW to select larger and larger enclosing blocks, or DOWN ARROW to select |
| 373 | smaller blocks. </p> |
| 374 | <p>Here are a few sample inputs and responses in Eclipse using the Display window.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 376 | <table width="100%" border="1"> |
| 377 | <tr> |
| 378 | <th scope="col">Input</th> |
| 379 | <th scope="col">Response</th> |
| 380 | </tr> |
| 381 | <tr> |
| 382 | <td><code>zip</code></td> |
| 383 | <td><code>(java.lang.String) |
| 384 | /work/device/out/linux-x86-debug/android/app/android_sdk.zip</code></td> |
| 385 | </tr> |
| 386 | <tr> |
| 387 | <td><code>zip.endsWith(".zip")</code></td> |
| 388 | <td><code>(boolean) true</code></td> |
| 389 | </tr> |
| 390 | <tr> |
| 391 | <td><code>zip.endsWith(".jar")</code></td> |
| 392 | <td><code>(boolean) false</code></td> |
| 393 | </tr> |
| 394 | </table> |
| 395 | <p>You can also execute arbitrary code when not debugging by using a scrapbook page. |
| 396 | Search the Eclipse documentation for "scrapbook".</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
| 398 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 399 | <h3>Running DDMS Manually</h3> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | |
| Scott Main | 9d8dd80 | 2009-04-21 19:17:59 -0700 | [diff] [blame] | 401 | <p>Although the recommended way to debug is to use the ADT plugin, you can manually run |
| 402 | DDMS and configure Eclipse to debug on port 8700. (<strong>Note: </strong>Be sure that you |
| 403 | have first started <a href="{@docRoot}guide/developing/tools/ddms.html">DDMS</a>). </p> |
| 404 | |
| 405 | |
| 406 | <!-- TODO: clean this up and expand it to cover more wizards and features |
| 407 | <h3>ADT Wizards</h3> |
| 408 | |
| 409 | <p>Notice that the "New Android Project" wizard has been expanded to use the multi-platform |
| 410 | capabilities of the new SDK.</p> |
| 411 | |
| 412 | <p>There is now a "New XML File" wizard that lets you create skeleton XML resource |
| 413 | files for your Android projects. This makes it easier to create a new layout, a new menu, a |
| 414 | new strings file, etc.</p> |
| 415 | |
| 416 | <p>Both wizards are available via <strong>File > New</strong> and new icons in the main |
| 417 | Eclipse toolbar (located to the left of the Debug and Run icons). |
| 418 | If you do not see the new icons, you may need to select <strong>Window > Reset |
| 419 | Perspective</strong> from the Java perspective.</p> |
| 420 | --> |