| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 1 | page.title=Developing In Other IDEs |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | @jd:body |
| 3 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -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> |
| 9 | <li><a href="#Signing">Preparing to Sign Your Application</a></li> |
| 10 | <li><a href="#Building">Building Your Application</a> |
| 11 | <ol> |
| 12 | <li><a href="#DebugMode">Building in debug mode</a></li> |
| 13 | <li><a href="#ReleaseMode">Building in release mode</a></li> |
| 14 | </ol> |
| 15 | </li> |
| 16 | <li><a href="#Running">Running Your Application</a></li> |
| 17 | <li><a href="#AttachingADebugger">Attaching a Debugger to Your Application</a></li> |
| 18 | </ol> |
| 19 | |
| 20 | <h2>See also</h2> |
| 21 | <ol> |
| Scott Main | 8a4c53a | 2009-04-24 13:41:44 -0700 | [diff] [blame] | 22 | <li><a href="{@docRoot}guide/developing/tools/othertools.html#android">android Tool</a></li> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 23 | <li><a href="{@docRoot}guide/developing/tools/emulator.html">Android Emulator</a></li> |
| 24 | <li><a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a></li> |
| 25 | </ol> |
| 26 | </div> |
| 27 | </div> |
| 28 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | <p>The recommended way to develop an Android application is to use |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 30 | <a href="{@docRoot}guide/developing/eclipse-adt.html">Eclipse with the ADT plugin</a>. |
| 31 | The ADT plugin provides editing, building, debugging, and .apk packaging and signing functionality |
| 32 | integrated right into the IDE.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 34 | <p>However, if you'd rather develop your application in another IDE, such as IntelliJ, |
| 35 | or in a basic editor, such as Emacs, you can do that instead. The SDK |
| 36 | includes all the tools you need to set up an Android project, build it, debug it and then |
| 37 | package it for distribution. This document is your guide to using these tools.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 40 | <h2 id="EssentialTools">Essential Tools</h2> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 42 | <p>When developing in IDEs or editors other than Eclipse, you'll require |
| 43 | familiarity with the following Android SDK tools:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 45 | <dl> |
| Scott Main | 8a4c53a | 2009-04-24 13:41:44 -0700 | [diff] [blame] | 46 | <dt><a href="{@docRoot}guide/developing/tools/othertools.html#android">android</a></dt> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 47 | <dd>To create/update Android projects and to create/move/delete AVDs.</dd> |
| 48 | <dt><a href="{@docRoot}guide/developing/tools/emulator.html">Android Emulator</a></dt> |
| 49 | <dd>To run your Android applications on an emulated Android platform.</dd> |
| 50 | <dt><a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a></dt> |
| 51 | <dd>To interface with your emulator or connected device (install apps, |
| 52 | shell the device, issue commands, etc.). |
| 53 | </dd> |
| 54 | </dl> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 56 | <p>In addition to the above tools, included with the SDK, you'll use the following |
| 57 | open source and third-party tools:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 59 | <dl> |
| 60 | <dt>Ant</dt> |
| 61 | <dd>To compile and build your Android project into an installable .apk file.</dd> |
| 62 | <dt>Keytool</dt> |
| 63 | <dd>To generate a keystore and private key, used to sign your .apk file.</dd> |
| 64 | <dt>Jarsigner (or similar signing tool)</dt> |
| 65 | <dd>To sign your .apk file with a private key generated by keytool.</dd> |
| 66 | </dl> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 68 | <p>In the topics that follow, you'll be introduced to each of these tools as necessary. |
| 69 | For more advanced operations, please read the respective documentation for each tool.</p> |
| 70 | |
| 71 | |
| 72 | <h2 id="CreatingAProject">Creating an Android Project</h2> |
| 73 | |
| 74 | <p>To create an Android project, you must use the <code>android</code> tool. When you create |
| 75 | a new project with <code>android</code>, it will generate a project directory |
| 76 | with some default application files, stub files, configuration files and a build file.</p> |
| 77 | |
| 78 | |
| 79 | <h3 id="CreatingANewProject">Creating a new Project</h3> |
| 80 | |
| 81 | <p>If you're starting a new project, use the <code>android create project</code> |
| 82 | command to generate all the necessary files and folders.</p> |
| 83 | |
| 84 | <p>To create a new Android project, open a command-line, |
| 85 | navigate to the <code>tools/</code> directory of your SDK and run:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | <pre> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 87 | android create project \ |
| 88 | --target <em><targetID></em> \ |
| 89 | --path <em>/path/to/your/project</em> \ |
| 90 | --activity <em><your_activity_name></em> \ |
| 91 | --package <em><your_package_namespace></em> |
| 92 | </pre> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | |
| 94 | <ul> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 95 | <li><code>target</code> is the "build target" for your application. It corresponds |
| 96 | to an Android platform library (including any add-ons, such as Google APIs) that you would like to |
| 97 | build your project against. To see a list of available targets and their corresponding IDs, |
| 98 | execute: <code>android list targets</code>.</li> |
| 99 | <li><code>path</code> is the location of your project directory. If the directory does not exist, |
| 100 | it will be created for you.</li> |
| 101 | <li><code>activity</code> is the name for your {@link android.app.Activity} class. This class file |
| 102 | will be created for you inside |
| 103 | <code><em><path_to_your_project></em>/src/<em><your_package_namespace_path></em>/</code>.</li> |
| 104 | <li><code>package</code> is the package namespace for your project, following the same rules as for |
| 105 | packages in the Java programming language.</li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | </ul> |
| 107 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 108 | <p>Here's an example:</p> |
| 109 | <pre> |
| 110 | android create project \ |
| 111 | --target 1 \ |
| 112 | --path ./myProject \ |
| 113 | --activity MyActivity \ |
| 114 | --package com.example.myproject |
| 115 | </pre> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 117 | <p>The tool generates the following files and directories:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 119 | <ul> |
| 120 | <li><code>AndroidManifest.xml</code> - The application manifest file, |
| 121 | synced to the specified Activity class for the project.</li> |
| 122 | <li><code>build.xml</code> - Build file for Ant.</li> |
| 123 | <li><code>default.properties</code> - Properties for the build system. <em>Do not modify |
| 124 | this file</em>.</li> |
| 125 | <li><code>build.properties</code> - Customizable properties for the build system. You can edit this |
| 126 | file to overried default build settings used by Ant.</li> |
| 127 | <li><code>src<em>/your/package/namespace/ActivityName</em>.java</code> - The Activity class |
| 128 | you specified during project creation.</li> |
| 129 | <li><code>bin/</code> - Output directory for the build script.</li> |
| 130 | <li><code>gen/</code> - Holds <code>Ant</code>-generated files, such as <code>R.java</code>. </li> |
| 131 | <li><code>libs/</code> - Holds private libraries.</li> |
| 132 | <li><code>res/</code> - Holds project resources.</li> |
| 133 | <li><code>src/</code> - Holds source code.</li> |
| 134 | <li><code>tests/</code> - Holds a duplicate of all-of-the-above, for testing purposes.</li> |
| 135 | </ul> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 137 | <p>Once you've created your project, you're ready to begin development. |
| 138 | You can move your project folder wherever you want for development, but keep in mind |
| 139 | that you must use the <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a> |
| 140 | (adb) — located in the SDK <code>tools/</code> directory — to send your application |
| 141 | to the emulator (discussed later). So you need access between your project solution and |
| 142 | the <code>tools/</code> folder.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 144 | <p class="warning"><strong>Note:</strong> You should refrain from moving the |
| 145 | location of the SDK directory, because this will break the build scripts. (They |
| 146 | will need to be manually updated to reflect the new SDK location before they will |
| 147 | work again.)</p> |
| 148 | |
| 149 | |
| 150 | <h3 id="UpdatingAProject">Updating a project</h3> |
| 151 | |
| 152 | <p>If you're upgrading a project from an older version of the Android SDK or want to create |
| 153 | a new project from existing code, use the |
| 154 | <code>android update project</code> command to update the project to the new development |
| 155 | environment. You can also use this command to revise the build target of an existing project |
| 156 | (with the <code>--target</code> option). The <code>android</code> tool will generate any files and |
| 157 | folders (listed in the previous section) that are either missing or need to be updated, |
| 158 | as needed for the Android project.</p> |
| 159 | |
| 160 | <p>To update an existing Android project, open a command-line |
| 161 | and navigate to the <code>tools/</code> directory of your SDK. Now run:</p> |
| 162 | <pre> |
| 163 | android update project --target <em><targetID></em> --path <em>path/to/your/project/</em> |
| 164 | </pre> |
| 165 | |
| 166 | <ul> |
| 167 | <li><code>target</code> is the "build target" for your application. It corresponds to |
| 168 | an Android platform library (including any add-ons, such as Google APIs) that you would |
| 169 | like to build your project against. To see a list of available targets and their corresponding IDs, |
| 170 | execute: <code>android list targets</code>.</li> |
| 171 | <li><code>path</code> is the location of your project directory.</li> |
| 172 | </ul> |
| 173 | |
| 174 | <p>Here's an example:</p> |
| 175 | <pre> |
| 176 | android update project --target 2 --path ./myProject |
| 177 | </pre> |
| 178 | |
| 179 | |
| 180 | <h2 id="Signing">Preparing to Sign Your Application</h2> |
| 181 | |
| 182 | <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] | 183 | Android applications must be digitally signed before the system will install |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 184 | them on an emulator or device. There are two ways to do this: |
| 185 | with a <em>debug key</em> (for immediate testing on an emulator or development device) |
| 186 | or with a <em>private key</em> (for application distribution).</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 188 | <p>The Android build tools help you get started by automatically signing your .apk |
| 189 | files with a debug key at build time. This means |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | that you can compile your application and install it on the emulator without |
| 191 | having to generate your own private key. However, please note that if you intend |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 192 | to publish your application, you <strong>must</strong> sign the application with your |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | own private key, rather than the debug key generated by the SDK tools. </p> |
| 194 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 195 | <p>Please read <a href="{@docRoot}guide/publishing/app-signing.html">Signing Your |
| 196 | Applications</a>, which provides a thorough guide to application signing on Android |
| 197 | and what it means to you as an Android application developer.</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | |
| 199 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 200 | |
| 201 | <h2 id="Building">Building Your Application</h2> |
| 202 | |
| 203 | <p>There are two ways to build your application: one for testing/debugging your application |
| 204 | — <em>debug mode</em> — and one for building your final package for release — |
| 205 | <em>release mode</em>. As described in the previous |
| 206 | section, your application must be signed before it can be installed on an emulator |
| 207 | or device.</p> |
| 208 | |
| 209 | <p>Whether you're building in debug mode or release mode, you |
| 210 | need to use the Ant tool to compile and build your project. This will create the .apk file |
| 211 | that is installed onto the emulator or device. When you build in debug mode, the .apk |
| 212 | file is automatically signed by the SDK tools with a debug key, so it's instantly ready for installation |
| 213 | (but only onto an emulator or attached development device). |
| 214 | When you build in release mode, the .apk file is <em>unsigned</em>, so you must manually |
| 215 | sign it with your own private key, using Keytool and Jarsigner.</p> |
| 216 | |
| 217 | <p>It's important that you read and understand |
| 218 | <a href="{@docRoot}guide/publishing/app-signing.html">Signing Your Applications</a>, particularly |
| 219 | once you're ready to release your application and share it with end-users. That document describes |
| 220 | the procedure for generating a private key and then using it to sign your .apk file. |
| 221 | If you're just getting started, however, |
| 222 | you can quickly run your applications on an emulator or your own development device by building in |
| 223 | debug mode.</p> |
| 224 | |
| 225 | <p>If you don't have Ant, you can obtain it from the |
| 226 | <a href="http://ant.apache.org/">Apache Ant home page</a>. Install it and make |
| 227 | sure it is in your executable PATH. Before calling Ant, you need to declare the JAVA_HOME |
| 228 | environment variable to specify the path to where the JDK is installed.</p> |
| 229 | |
| 230 | <p class="note"><strong>Note:</strong> When installing JDK on Windows, the default is to install |
| 231 | in the "Program Files" directory. This location will cause <code>ant</code> to fail, because of |
| 232 | the space. To fix the problem, you can specify the JAVA_HOME variable like this: |
| 233 | <code>set JAVA_HOME=c:\Prora~1\Java\<jdkdir></code>. The easiest solution, however, is to |
| 234 | install JDK in a non-space directory, for example: <code>c:\java\jdk1.6.0_02</code>.</p> |
| 235 | |
| 236 | |
| 237 | <h3 id="DebugMode">Building in debug mode</h3> |
| 238 | |
| 239 | <p>For immediate application testing and debugging, you can build your application |
| 240 | in debug mode and immediately install it on an emulator. In debug mode, the build tools automatically |
| 241 | sign your application with a debug key. However, you can (and should) also test your |
| 242 | application in release mode. Debug mode simply allows you to run your application without |
| 243 | manually signing the application.</p> |
| 244 | |
| 245 | <p>To build in debug mode:</p> |
| 246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | <ol> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 248 | <li>Open a command-line and navigate to the root of your project directory.</li> |
| 249 | <li>Use Ant to compile your project in debug mode: |
| 250 | <pre>ant debug</pre> |
| 251 | <p>This creates your Android application .apk file inside the project <code>bin/</code> |
| 252 | directory, named <code><em><your_DefaultActivity_name></em>-debug.apk</code>. The file |
| 253 | is already signed with the debug key.</p> |
| 254 | </li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | </ol> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 257 | <p>Each time you change a source file or resource, you must run Ant |
| 258 | again in order to package up the latest version of the application.</p> |
| 259 | |
| 260 | <p>To install and run your application on an emulator, see the following section |
| 261 | about <a href="#Running">Running Your Application</a>.</p> |
| 262 | |
| 263 | |
| 264 | <h3 id="ReleaseMode">Building in release mode</h3> |
| 265 | |
| 266 | <p>When you're ready to release and distribute your application to end-users, you must build |
| 267 | your application in release mode. Once you have built in release mode, it's a good idea to perform |
| 268 | additional testing and debugging with the final .apk.</p> |
| 269 | |
| 270 | <p>To build in release mode:</p> |
| 271 | |
| 272 | <ol> |
| 273 | <li>Open a command-line and navigate to the root of your project directory.</li> |
| 274 | <li>Use Ant to compile your project in release mode: |
| 275 | <pre>ant release</pre> |
| 276 | <p>This creates your Android application .apk file inside the project <code>bin/</code> |
| 277 | directory, named <code><em><your_DefaultActivity_name></em>.apk</code>.</p> |
| 278 | <p class="note"><strong>Note:</strong> The .apk file is <em>unsigned</em> at this point. |
| 279 | You can't install it on an emulator or device until you sign it with your private key.</p> |
| 280 | </li> |
| 281 | </ol> |
| 282 | |
| 283 | <p>Because release mode builds your application unsigned, your next step is to sign |
| 284 | it with your private key, in order to distribute it to end-users. To complete this procedure, |
| 285 | read <a href="{@docRoot}guide/publishing/app-signing.html">Signing Your Applications</a>.</p> |
| 286 | |
| 287 | <p>Once you have signed your application with a private key, you can install it on an |
| 288 | emulator or device as discussed in the following section about |
| 289 | <a href="#Running">Running Your Application</a>. |
| 290 | You can also try installing it onto a device from a web server. |
| 291 | Simply upload the signed APK to a web site, then load the .apk URL in your Android web browser to |
| 292 | download the application and begin installation. |
| 293 | (On your device, be sure you have enabled <em>Settings > Applications > Unknown sources</em>.)</p> |
| 294 | |
| 295 | |
| 296 | <h2 id="Running">Running Your Application</h2> |
| 297 | |
| 298 | <p>Unless you'll be running your application on device hardware, |
| 299 | you need to launch an emulator upon which you will install your application. |
| 300 | An instance of the Android emulator runs a specific Android platform with specific device configuration |
| 301 | settings. The platform and configuration is defined with an Android Virtual Device (AVD). |
| 302 | So before you can launch your emulator, you must define an AVD.</p> |
| 303 | |
| 304 | <p>If you'll be running your application on device hardware, please read about |
| 305 | <a href="{@docRoot}guide/developing/device.html">Developing On a Device</a> instead.</p> |
| 306 | |
| 307 | <ol> |
| 308 | <li><strong>Create an AVD</strong> |
| 309 | <ol> |
| 310 | <li>Open a command-line and navigate to your SDK package's |
| 311 | <code>tools/</code> directory.</li> |
| 312 | <li>First, you need to select a "deployment target." To view available targets, execute: |
| 313 | <pre>android list targets</pre> |
| 314 | <p>This will output a list of available Android targets, such as:</p> |
| 315 | <pre> |
| 316 | id:1 |
| 317 | Name: Android 1.1 |
| 318 | Type: platform |
| 319 | API level: 2 |
| 320 | Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P |
| 321 | id:2 |
| 322 | Name: Android 1.5 |
| 323 | Type: platform |
| 324 | API level: 3 |
| 325 | Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P |
| 326 | </pre> |
| 327 | <p>Find the target that matches the Android platform upon which you'd like |
| 328 | to run your application. Note the integer value of the <code>id</code> — |
| 329 | you'll use this in the next step.</p> |
| 330 | </li> |
| 331 | <li>Create a new AVD using your selected deployment target: |
| 332 | <pre>android create avd --name <em><your_avd_name></em> --target <em><targetID></em></pre> |
| 333 | <li>Next, you'll be asked whether you'd like to create a custom hardware profile. |
| 334 | If you respond "yes," you'll be presented with a series of prompts to define various aspects of the |
| 335 | device hardware (leave entries blank to use default values, which are shown in brackets). Otherwise, |
| 336 | press return to use all default values ("no" is the default).</li> |
| 337 | </li> |
| 338 | </ol> |
| 339 | </li> |
| 340 | |
| 341 | <li><strong>Launch an emulator</strong></li> |
| 342 | <p>From your SDK's <code>tools/</code> directory, launch an emulator |
| 343 | using an existing AVD (created above): |
| 344 | <pre>emulator -avd <em><your_avd_name></em></pre> |
| 345 | <p>An instance of the emulator will now launch, running the target and configuration |
| 346 | defined by your AVD.</p> |
| 347 | </li> |
| 348 | |
| 349 | <li><strong>Install your application</strong> |
| 350 | <p>From your SDK's <code>tools/</code> directory, install the .apk on the emulator: |
| 351 | <pre>adb install <em>/path/to/your/application</em>.apk</pre> |
| 352 | <p>If there is more than one emulator running, you must specify the emulator upon which to install |
| 353 | the application, by its serial number, with the <code>-s</code> option. For example:</p> |
| 354 | <pre>adb -s emulator-5554 install /my/project/path/myapp.apk</pre> |
| 355 | </li> |
| 356 | <li><strong>Open your application</strong> |
| 357 | <p>In the emulator, open the list of available applications to find |
| 358 | and open your application.</p> |
| 359 | </li> |
| 360 | </ol> |
| 361 | |
| 362 | <p>If you don't see your application on the emulator. Try restarting the emulator |
| 363 | (with the same AVD). Sometimes when you install an Activity for the |
| 364 | first time, it won't show up in the application launcher or be accessible by other |
| 365 | applications. This is because the package manager usually examines manifests |
| 366 | completely only on emulator startup.</p> |
| 367 | |
| 368 | <p class="note"><strong>Tip:</strong> If you have only one emulator running, |
| 369 | you can build your application and install it on the emulator in one simple step. |
| 370 | Navigate to the root of your project directory and use Ant to compile the project |
| 371 | with <em>install mode</em>: |
| 372 | <code>ant install</code>. This will build your application, sign it with the debug key, |
| 373 | and install it on the currently running emulator. |
| 374 | If there is more than one emulator currently running |
| 375 | when using the <code>install</code> command, it will fail — it can't select between the |
| 376 | multiple emulators.</p> |
| 377 | |
| 378 | <p>For more information on the tools used above, please see the following documents:</p> |
| 379 | <ul> |
| Scott Main | 8a4c53a | 2009-04-24 13:41:44 -0700 | [diff] [blame] | 380 | <li><a href="{@docRoot}guide/developing/tools/othertools.html#android">android Tool</a></li> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 381 | <li><a href="{@docRoot}guide/developing/tools/emulator.html">Android Emulator</a></li> |
| 382 | <li><a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a> (ADB)</li> |
| 383 | </ul> |
| 384 | |
| 385 | |
| 386 | <h2 id="AttachingADebugger">Attaching a Debugger to Your Application</h2> |
| 387 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | <p>This section describes how to display debug information on the screen (such |
| 389 | as CPU usage), as well as how to hook up your IDE to debug running applications |
| 390 | on the emulator. </p> |
| 391 | |
| 392 | <p>Attaching a debugger is automated using the Eclipse plugin, |
| 393 | but you can configure other IDEs to listen on a debugging port to receive debugging |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 394 | information:</p> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | <ol> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 396 | <li><strong>Start the <a href="{@docRoot}guide/developing/tools/ddms.html">Dalvik Debug Monitor |
| 397 | Server (DDMS)</a> tool, </strong> which |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | acts as a port forwarding service between your IDE and the emulator.</li> |
| 399 | <li><strong>Set |
| 400 | optional debugging configurations on |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 401 | your emulator</strong>, such as blocking application startup for an Activity |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | until a debugger is attached. Note that many of these debugging options |
| 403 | can be used without DDMS, such as displaying CPU usage or screen refresh |
| 404 | rate on the emulator.</li> |
| Scott Main | bd13c24 | 2009-04-21 19:09:24 -0700 | [diff] [blame] | 405 | <li><strong>Configure your IDE to attach to port 8700 for debugging.</strong> Read |
| 406 | about <a href="{@docRoot}guide/developing/debug-tasks.html#ide-debug-port"> |
| 407 | Configuring Your IDE to Attach to the Debugging Port</a>. </li> |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | </ol> |