Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1 | page.title=Android Debug Bridge |
| 2 | parent.title=Tools |
| 3 | parent.link=index.html |
Joe Fernandez | 33baa5a | 2013-11-14 11:41:19 -0800 | [diff] [blame] | 4 | page.tags=adb |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 5 | @jd:body |
| 6 | |
| 7 | <div id="qv-wrapper"> |
| 8 | <div id="qv"> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 9 | <h2>In this document</h2> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 10 | <ol> |
| 11 | <li><a href="#issuingcommands">Syntax</a></li> |
| 12 | <li><a href="#commandsummary">Commands</a></li> |
| 13 | <li><a href="#devicestatus">Querying for Emulator/Device Instances</a></li> |
| 14 | <li><a href="#directingcommands">Directing Commands to a Specific Emulator/Device Instance</a></li> |
| 15 | <li><a href="#move">Installing an Application</a></li> |
| 16 | <li><a href="#forwardports">Forwarding Ports</a></li> |
| 17 | <li><a href="#copyfiles">Copying Files to or from an Emulator/Device Instance</a></li> |
| 18 | <li><a href="#shellcommands">Issuing Shell Commands</a> |
| 19 | <ol> |
| 20 | <li><a href="#am">Using activity manager (am)</a></li> |
| 21 | <li><a href="#pm">Using package manager (pm)</a></li> |
| 22 | <li><a href="#sqlite">Examining sqlite3 databases from a remote shell</a></li> |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 23 | <li><a href="#screenrecord">Recording a device screen</a></li> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 24 | <li><a href="#monkey">UI/Application Exerciser Monkey</a></li> |
| 25 | <li><a href="#othershellcommands">Other shell commands</a></li> |
| 26 | </ol> |
| 27 | </li> |
| 28 | <li><a href="#logcat">Enabling logcat logging</a></li> |
| 29 | <li><a href="#stopping">Stopping the adb server</a></li> |
Glenn Kasten | 77c8626 | 2014-02-03 14:01:25 -0800 | [diff] [blame] | 30 | <li><a href="#wireless">Wireless usage</a></li> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 31 | </ol> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 32 | |
| 33 | </div> |
| 34 | </div> |
| 35 | |
| 36 | <p>Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an |
| 37 | emulator instance or connected Android-powered device. It is a client-server program that includes |
| 38 | three components: </p> |
| 39 | |
| 40 | <ul> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 41 | <li>A client, which runs on your development machine. You can invoke a client from a shell |
| 42 | by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create |
| 43 | adb clients. </li> |
| 44 | <li>A server, which runs as a background process on your development machine. The server |
| 45 | manages communication between the client and the adb daemon running on an emulator or device. </li> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 46 | <li>A daemon, which runs as a background process on each emulator or device instance. </li> |
| 47 | </ul> |
| 48 | |
| 49 | <p>You can find the {@code adb} tool in {@code <sdk>/platform-tools/}.</p> |
| 50 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 51 | <p>When you start an adb client, the client first checks whether there is an adb server |
| 52 | process already running. If there isn't, it starts the server process. When the server starts, |
| 53 | it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb |
| 54 | clients use port 5037 to communicate with the adb server. </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 55 | |
| 56 | <p>The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example: </p> |
| 57 | |
| 58 | <p style="margin-left:2em"> |
| 59 | Emulator 1, console: 5554<br/> |
| 60 | Emulator 1, adb: 5555<br> |
| 61 | Emulator 2, console: 5556<br> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 62 | Emulator 2, adb: 5557<br> |
| 63 | and so on... |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 64 | </p> |
| 65 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 66 | <p>As shown, the emulator instance connected to adb on port 5555 is the same as the instance |
| 67 | whose console listens on port 5554. </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 68 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 69 | <p>Once the server has set up connections to all emulator instances, you can use adb commands to |
| 70 | access those instances. Because the server manages connections to emulator/device |
| 71 | instances and handles commands from multiple adb clients, you can control any emulator/device |
| 72 | instance from any client (or from a script).</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 73 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 74 | |
Scott Main | 03c54e7 | 2013-02-05 14:05:36 -0800 | [diff] [blame] | 75 | <p class="note"><strong>Note:</strong> When you connect a device running Android 4.2.2 or higher |
| 76 | to your computer, the system shows a dialog asking whether to accept an RSA key that allows |
| 77 | debugging through this computer. This security mechanism protects user devices because it ensures |
| 78 | that USB debugging and other adb commands cannot be executed unless you're able to unlock the |
| 79 | device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with |
| 80 | SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or |
| 81 | higher.</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 82 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 83 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 84 | <h2 id="issuingcommands">Syntax</h2> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 85 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 86 | <p>You can issue adb commands from a command line on your development machine or from a script. |
| 87 | The usage is: </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 88 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 89 | <pre class="no-pretty-print"> |
| 90 | adb [-d|-e|-s <serialNumber>] <command> |
| 91 | </pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 92 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 93 | <p>If there's only one emulator running or only one device connected, the adb command is |
| 94 | sent to that device by default. If multiple emulators are running and/or multiple devices are |
| 95 | attached, you need to use the <code>-d</code>, <code>-e</code>, or <code>-s</code> |
| 96 | option to specify the target device to which the command should be directed. </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 97 | |
| 98 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 99 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 100 | <h2 id="commandsummary">Commands</h2> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 101 | |
| 102 | <p>The table below lists all of the supported adb commands and explains their meaning and usage. </p> |
| 103 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 104 | <p class="table-caption"><strong>Table 1.</strong> Available adb commands</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 105 | <table> |
| 106 | <tr> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 107 | <th>Category</th> |
| 108 | <th>Command</th> |
| 109 | <th>Description</th> |
| 110 | <th>Comments</th> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 111 | </tr> |
| 112 | |
| 113 | <tr> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 114 | <td rowspan="3">Target Device</td> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 115 | <td><code>-d</code></td> |
| 116 | <td>Direct an adb command to the only attached USB device.</td> |
| 117 | <td>Returns an error if more than one USB device is attached.</td> |
| 118 | </tr> |
| 119 | |
| 120 | <tr> |
| 121 | <td><code>-e</code></td> |
| 122 | <td>Direct an adb command to the only running emulator instance.</td> |
| 123 | <td>Returns an error if more than one emulator instance is running. </td> |
| 124 | </tr> |
| 125 | |
| 126 | <tr> |
| 127 | <td><code>-s <serialNumber></code></td> |
| 128 | <td>Direct an adb command a specific emulator/device instance, referred to by its adb-assigned serial number (such as "emulator-5556").</td> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 129 | <td>See <a href="#directingcommands">Directing |
| 130 | Commands to a Specific Emulator/Device Instance</a>.</td> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 131 | </tr> |
| 132 | |
| 133 | <tr> |
| 134 | <td rowspan="3">General</td> |
| 135 | <td><code>devices</code></td> |
| 136 | <td>Prints a list of all attached emulator/device instances.</td> |
| 137 | <td>See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information.</td> |
| 138 | </tr> |
| 139 | |
| 140 | <tr> |
| 141 | <td><code>help</code></td> |
| 142 | <td>Prints a list of supported adb commands.</td> |
| 143 | <td> </td> |
| 144 | </tr> |
| 145 | |
| 146 | <tr> |
| 147 | <td><code>version</code></td> |
| 148 | <td>Prints the adb version number. </td> |
| 149 | <td> </td> |
| 150 | </tr> |
| 151 | |
| 152 | <tr> |
| 153 | <td rowspan="3">Debug</td> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 154 | <td ><code>logcat [option] [filter-specs]</code></td> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 155 | <td>Prints log data to the screen. </td> |
| 156 | <td> </td> |
| 157 | </tr> |
| 158 | |
| 159 | <tr> |
| 160 | <td><code>bugreport</code></td> |
| 161 | <td>Prints <code>dumpsys</code>, <code>dumpstate</code>, and <code>logcat</code> data to the screen, for the purposes of bug reporting. </td> |
| 162 | <td> </td> |
| 163 | </tr> |
| 164 | |
| 165 | <tr> |
| 166 | <td><code>jdwp</code></td> |
| 167 | <td>Prints a list of available JDWP processes on a given device. </td> |
| 168 | <td>You can use the <code>forward jdwp:<pid></code> port-forwarding specification to connect to a specific JDWP process. For example: <br> |
| 169 | <code>adb forward tcp:8000 jdwp:472</code><br> |
| 170 | <code>jdb -attach localhost:8000</code></p> |
| 171 | </td> |
| 172 | </tr> |
| 173 | |
| 174 | <tr> |
| 175 | <td rowspan=3">Data</td> |
| 176 | <td><code>install <path-to-apk></code></td> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 177 | <td>Pushes an Android application (specified as a full path to an .apk file) to an emulator/device. </td> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 178 | <td> </td> |
| 179 | </tr> |
| 180 | |
| 181 | <tr> |
| 182 | <td><code>pull <remote> <local></code></td> |
| 183 | <td>Copies a specified file from an emulator/device instance to your development computer. </td> |
| 184 | <td> </td> |
| 185 | </tr> |
| 186 | |
| 187 | <tr> |
| 188 | <td><code>push <local> <remote></code></td> |
| 189 | <td>Copies a specified file from your development computer to an emulator/device instance. </td> |
| 190 | <td> </td> |
| 191 | </tr> |
| 192 | |
| 193 | <tr> |
| 194 | <td rowspan="2">Ports and Networking</td> |
| 195 | <td><code>forward <local> <remote></code></td> |
| 196 | <td>Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance. </td> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 197 | <td>Port specifications can use these schemes: |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 198 | <ul><li><code>tcp:<portnum></code></li> |
| 199 | <li><code>local:<UNIX domain socket name></code></li> |
| 200 | <li><code>dev:<character device name></code></li> |
| 201 | <li><code>jdwp:<pid></code></li></ul> |
| 202 | </td> |
| 203 | </tr> |
| 204 | |
| 205 | <tr> |
| 206 | <td><code>ppp <tty> [parm]...</code></td> |
| 207 | <td>Run PPP over USB. |
| 208 | <ul> |
| 209 | <li><code><tty></code> — the tty for PPP stream. For example <code>dev:/dev/omap_csmi_ttyl</code>. </li> |
| 210 | <li><code>[parm]... </code> — zero or more PPP/PPPD options, such as <code>defaultroute</code>, <code>local</code>, <code>notty</code>, etc.</li></ul> |
| 211 | |
| 212 | <p>Note that you should not automatically start a PPP connection. </p></td> |
| 213 | <td></td> |
| 214 | </tr> |
| 215 | |
| 216 | <tr> |
| 217 | <td rowspan="3">Scripting</td> |
| 218 | <td><code>get-serialno</code></td> |
| 219 | <td>Prints the adb instance serial number string.</td> |
| 220 | <td rowspan="2">See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information. </td> |
| 221 | </tr> |
| 222 | |
| 223 | <tr> |
| 224 | <td><code>get-state</code></td> |
| 225 | <td>Prints the adb state of an emulator/device instance.</td> |
| 226 | </td> |
| 227 | </tr> |
| 228 | |
| 229 | <tr> |
| 230 | <td><code>wait-for-device</code></td> |
| 231 | <td>Blocks execution until the device is online — that is, until the instance state is <code>device</code>.</td> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 232 | <td>You can prepend this command to other adb commands, in which case adb will wait until the emulator/device instance is connected before issuing the other commands. Here's an example: |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 233 | <pre class="no-pretty-print">adb wait-for-device shell getprop</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 234 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 235 | Note that this command does <em>not</em> cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system. As an example, the <code>install</code> requires the Android package manager, which is available only after the system is fully booted. A command such as |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 236 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 237 | <pre class="no-pretty-print">adb wait-for-device install <app>.apk</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 238 | |
| 239 | would issue the <code>install</code> command as soon as the emulator or device instance connected to the adb server, but before the Android system was fully booted, so it would result in an error. </td> |
| 240 | </tr> |
| 241 | |
| 242 | |
| 243 | |
| 244 | <tr> |
| 245 | <td rowspan="2">Server</td> |
| 246 | <td><code>start-server</code></td> |
| 247 | <td>Checks whether the adb server process is running and starts it, if not.</td> |
| 248 | <td> </td> |
| 249 | </tr> |
| 250 | |
| 251 | <tr> |
| 252 | <td><code>kill-server</code></td> |
| 253 | <td>Terminates the adb server process.</td> |
| 254 | <td> </td> |
| 255 | </tr> |
| 256 | |
| 257 | |
| 258 | |
| 259 | <tr> |
| 260 | <td rowspan="2">Shell</td> |
| 261 | <td><code>shell</code></td> |
| 262 | <td>Starts a remote shell in the target emulator/device instance.</td> |
| 263 | <td rowspan="2">See <a href="#shellcommands">Issuing Shell Commands</a> for more information. </td> |
| 264 | </tr> |
| 265 | |
| 266 | <tr> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 267 | <td><code>shell [shellCommand]</code></td> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 268 | <td>Issues a shell command in the target emulator/device instance and then exits the remote shell.</td> |
| 269 | </tr> |
| 270 | |
| 271 | </table> |
| 272 | |
| 273 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 274 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 275 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 276 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 277 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 278 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 279 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 280 | |
| 281 | |
| 282 | <h2 id="devicestatus">Querying for Emulator/Device Instances</h2> |
| 283 | |
| 284 | <p>Before issuing adb commands, it is helpful to know what emulator/device instances are connected to the adb server. You can generate a list of attached emulators/devices using the <code>devices</code> command: </p> |
| 285 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 286 | <pre class="no-pretty-print">adb devices</pre> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 287 | |
| 288 | <p>In response, adb prints this status information for each instance:</p> |
| 289 | |
| 290 | <ul> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 291 | <li>Serial number — A string created by adb to uniquely identify an emulator/device instance by its |
| 292 | console port number. The format of the serial number is <code><type>-<consolePort></code>. |
| 293 | Here's an example serial number: <code>emulator-5554</code></li> |
| 294 | <li>State — The connection state of the instance may be one of the following: |
| 295 | <ul> |
| 296 | <li><code>offline</code> — the instance is not connected to adb or is not responding.</li> |
| 297 | <li><code>device</code> — the instance is now connected to the adb server. Note that this state does not |
| 298 | imply that the Android system is fully booted and operational, since the instance connects to adb |
| 299 | while the system is still booting. However, after boot-up, this is the normal operational state of |
| 300 | an emulator/device instance.</li> |
| 301 | <li><code>no device</code> — there is no emulator/device connected. |
| 302 | </ul> |
| 303 | </li> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 304 | </ul> |
| 305 | |
| 306 | <p>The output for each instance is formatted like this: </p> |
| 307 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 308 | <pre class="no-pretty-print">[serialNumber] [state]</pre> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 309 | |
| 310 | <p>Here's an example showing the <code>devices</code> command and its output:</p> |
| 311 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 312 | <pre class="no-pretty-print">adb devices |
| 313 | List of devices attached |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 314 | emulator-5554 device |
| 315 | emulator-5556 device |
| 316 | emulator-5558 device</pre> |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | <h2 id="directingcommands">Directing Commands to a Specific Emulator/Device Instance</h2> |
| 324 | |
| 325 | <p>If multiple emulator/device instances are running, you must specify a target instance |
| 326 | when issuing adb commands. To do so, use the <code>-s</code> option in the commands. The usage |
| 327 | for the <code>-s</code> option is:</p> |
| 328 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 329 | <pre class="no-pretty-print">adb -s <serialNumber> <command> </pre> |
| 330 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 331 | <p>As shown, you specify the target instance for a command using its adb-assigned serial number. |
| 332 | You can use the <code>devices</code> command to obtain the serial numbers of running |
| 333 | emulator/device instances. For example: </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 334 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 335 | <pre class="no-pretty-print">adb -s emulator-5556 install helloWorld.apk</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 336 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 337 | <p>Note that, if you issue a command without specifying a target emulator/device instance |
| 338 | while multiple devices are available, adb generates an error. |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 339 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 340 | <p>If you have multiple devices available (hardware or emulated), but only one is an emulator, |
| 341 | simply use the {@code -e} option to send commands to the emulator. Likewise if there's multiple |
| 342 | devices but only one hardware device attached, use the {@code -d} option to send commands to |
| 343 | the hardware device. |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 344 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 345 | |
| 346 | |
| 347 | |
| 348 | <h2 id="move">Installing an Application</h2> |
| 349 | <p>You can use adb to copy an application from your development computer and install it on an emulator/device instance. To do so, use the <code>install</code> command. With the command, you must specify the path to the .apk file that you want to install:</p> |
| 350 | |
| 351 | <pre class="no-pretty-print">adb install <path_to_apk></pre> |
| 352 | |
| 353 | <p>For more information about how to create an .apk file that you can install on an emulator/device |
| 354 | instance, see <a href="{@docRoot}tools/building/index.html">Building and Running</a></p> |
| 355 | |
| 356 | <p>Note that, if you are using the Eclipse IDE and have the ADT plugin installed, you do not need to use adb (or aapt) directly to install your application on the emulator/device. Instead, the ADT plugin handles the packaging and installation of the application for you. </p> |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | <h2 id="forwardports">Forwarding Ports</h2> |
| 364 | |
| 365 | <p>You can use the <code>forward</code> command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 6100 to emulator/device port 7100:</p> |
| 366 | <pre class="no-pretty-print">adb forward tcp:6100 tcp:7100</pre> |
| 367 | <p>You can also use adb to set up forwarding to named abstract UNIX domain sockets, as illustrated here:</p> |
| 368 | <pre class="no-pretty-print">adb forward tcp:6100 local:logd </pre> |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | <h2 id="copyfiles">Copying Files to or from an Emulator/Device Instance</h2> |
| 375 | |
| 376 | <p>You can use the adb commands <code>pull</code> and <code>push</code> to copy files to |
| 377 | and from an emulator/device instance. Unlike the <code>install</code> command, |
| 378 | which only copies an APK file to a specific location, the <code>pull</code> and <code>push</code> |
| 379 | commands let you copy arbitrary directories and files to any location in an |
| 380 | emulator/device instance. </p> |
| 381 | |
| 382 | <p>To copy a file or directory (and its sub-directories) <em>from</em> the emulator or device, use</p> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 383 | <pre class="no-pretty-print">adb pull <remote> <local></pre> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 384 | |
| 385 | <p>To copy a file or directory (and its sub-directories) <em>to</em> the emulator or device, use</p> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 386 | <pre class="no-pretty-print">adb push <local> <remote></pre> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 387 | |
| 388 | <p>In the commands, <code><local></code> and <code><remote></code> refer to the |
| 389 | paths to the target files/directory on your development machine (local) and on the |
| 390 | emulator/device instance (remote). For example: </p> |
| 391 | <pre class="no-pretty-print">adb push foo.txt /sdcard/foo.txt</pre> |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | <h2 id="shellcommands">Issuing Shell Commands</h2> |
| 402 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 403 | <p>Adb provides a Unix shell that you can use to run a variety of commands on an emulator |
| 404 | or connected device. The command binaries are stored in the file system of the emulator or device, |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 405 | at <code>/system/bin/...</code> |
| 406 | |
| 407 | <p>Two of the most common command tools are <a href="#am">activity manager</a> ({@code am}) and |
| 408 | <a href="#pm">package manager</a> ({@code pm}).</p> |
| 409 | |
| 410 | <p>You can use the <code>shell</code> command to issue commands, with or without entering |
| 411 | the adb remote shell on the emulator/device. To issue a single command without entering a |
| 412 | remote shell, use the <code>shell</code> command like this: </p> |
| 413 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 414 | <pre class="no-pretty-print">adb [-d|-e|-s <serialNumber>] shell <shell_command></pre> |
| 415 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 416 | <p>Or enter a remote shell on an emulator/device like this:</p> |
| 417 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 418 | <pre class="no-pretty-print">adb [-d|-e|-s <serialNumber>] shell</pre> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 419 | |
| 420 | <p>When you are ready to exit the remote shell, press CTRL+D or type |
| 421 | <code>exit</code>. </p> |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | <h3 id="am">Using activity manager (am)</h3> |
| 428 | |
| 429 | <p>Within an adb shell, you can issue commands with the activity manager ({@code am}) tool to |
| 430 | perform various system actions, such as start an activity, force-stop a process, |
| 431 | broadcast an intent, modify the device screen properties, and more. While in a shell, |
| 432 | the syntax is:</p> |
| 433 | <pre class="no-pretty-print"> |
| 434 | am <command> |
| 435 | </pre> |
| 436 | |
| 437 | <p>You can also issue an activity manager command directly from adb |
| 438 | without entering a remote shell. For example:</p> |
| 439 | <pre class="no-pretty-print"> |
| 440 | adb shell am start -a android.intent.action.VIEW |
| 441 | </pre> |
| 442 | |
| 443 | |
| 444 | <p class="table-caption"><strong>Table 2.</strong> Available activity manager commands</p> |
| 445 | <table> |
| 446 | <tr> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 447 | <th>Command</th> |
| 448 | <th>Description</th> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 449 | </tr> |
| 450 | |
| 451 | <tr> |
| 452 | <td><code> |
| 453 | start [options] <INTENT> |
| 454 | </code></td> |
| 455 | <td>Start an {@link android.app.Activity} specified by {@code <INTENT>}. <p>See the |
| 456 | <a href="#IntentSpec">Specification for <INTENT> arguments</a>. |
| 457 | <p>Options are: |
| 458 | <ul> |
| 459 | <li>{@code -D}: Enable debugging. |
| 460 | <li>{@code -W}: Wait for launch to complete. |
| 461 | <li>{@code --start-profiler <FILE>}: Start profiler and send results to {@code <FILE>}. |
| 462 | <li>{@code -P <FILE>}: Like <code>--start-profiler</code>, |
| 463 | but profiling stops when the app goes idle. |
| 464 | <li>{@code -R}: Repeat the activity launch {@code <COUNT>} times. Prior to each repeat, |
| 465 | the top activity will be finished. |
| 466 | <li>{@code -S}: Force stop the target app before starting the activity. |
| 467 | <li>{@code --opengl-trace}: Enable tracing of OpenGL functions. |
| 468 | <li>{@code --user <USER_ID> | current}: Specify which user to run as; if not |
| 469 | specified, then run as the current user. |
| 470 | </ul> |
| 471 | </td> |
| 472 | </tr> |
| 473 | |
| 474 | <tr> |
| 475 | <td><code> |
| 476 | startservice [options] <INTENT> |
| 477 | </code></td> |
| 478 | <td>Start the {@link android.app.Service} specified by {@code <INTENT>}. <p>See the |
| 479 | <a href="#IntentSpec">Specification for <INTENT> arguments</a>. |
| 480 | <p>Options are: |
| 481 | <ul> |
| 482 | <li>{@code --user <USER_ID> | current}: Specify which user to run as; if not |
| 483 | specified, then run as the current user. |
| 484 | </ul> |
| 485 | </td> |
| 486 | </tr> |
| 487 | |
| 488 | <tr> |
| 489 | <td><code> |
| 490 | force-stop <PACKAGE> |
| 491 | </code></td> |
| 492 | <td>Force stop everything associated with {@code <PACKAGE>} (the app's package name). |
| 493 | </td> |
| 494 | </tr> |
| 495 | |
| 496 | <tr> |
| 497 | <td><code> |
| 498 | kill [options] <PACKAGE> |
| 499 | </code></td> |
| 500 | <td> Kill all processes associated with {@code <PACKAGE>} |
| 501 | (the app's package name). This command kills only |
| 502 | processes that are safe to kill and that will not impact the user |
| 503 | experience. |
| 504 | <p>Options are: |
| 505 | <ul> |
| 506 | <li>{@code --user <USER_ID> | all | current}: Specify user whose processes to kill; |
| 507 | all users if not specified. |
| 508 | </ul> |
| 509 | </td> |
| 510 | </tr> |
| 511 | |
| 512 | <tr> |
| 513 | <td><code> |
| 514 | kill-all |
| 515 | </code></td> |
| 516 | <td>Kill all background processes. |
| 517 | </td> |
| 518 | </tr> |
| 519 | |
| 520 | <tr> |
| 521 | <td><code> |
| 522 | broadcast [options] <INTENT> |
| 523 | </code></td> |
| 524 | <td>Issue a broadcast intent. <p>See the |
| 525 | <a href="#IntentSpec">Specification for <INTENT> arguments</a>. |
| 526 | <p>Options are: |
| 527 | <ul> |
| 528 | <li>{@code [--user <USER_ID> | all | current]}: Specify which user to send to; if not |
| 529 | specified then send to all users. |
| 530 | </ul> |
| 531 | </td> |
| 532 | </tr> |
| 533 | |
| 534 | <tr> |
| 535 | <td><code> |
| 536 | instrument [options] <COMPONENT> |
| 537 | </code></td> |
| 538 | <td>Start monitoring with an {@link android.app.Instrumentation} instance. |
| 539 | Typically the target {@code <COMPONENT>} |
| 540 | is the form {@code <TEST_PACKAGE>/<RUNNER_CLASS>}. <p>Options are: |
| 541 | <ul> |
| 542 | <li>{@code -r}: Print raw results (otherwise decode |
| 543 | {@code <REPORT_KEY_STREAMRESULT>}). Use with |
| 544 | {@code [-e perf true]} to generate raw output for performance measurements. |
| 545 | |
| 546 | <li>{@code -e <NAME> <VALUE>}: Set argument {@code <NAME>} to {@code <VALUE>}. |
| 547 | For test runners a common form is {@code |
| 548 | -e <testrunner_flag> <value>[,<value>...]}. |
| 549 | |
| 550 | <li>{@code -p <FILE>}: Write profiling data to {@code <FILE>}. |
| 551 | |
| 552 | <li>{@code -w}: Wait for instrumentation to finish before returning. Required for |
| 553 | test runners. |
| 554 | |
| 555 | <li>{@code --no-window-animation}: Turn off window animations while running. |
| 556 | <li>{@code --user <USER_ID> | current}: Specify which user instrumentation runs in; |
| 557 | current user if not specified. |
| 558 | </ul> |
| 559 | |
| 560 | </td> |
| 561 | </tr> |
| 562 | |
| 563 | <tr> |
| 564 | <td><code> |
| 565 | profile start <PROCESS> <FILE> |
| 566 | </code></td> |
| 567 | <td>Start profiler on {@code <PROCESS>}, write results to {@code <FILE>}. |
| 568 | </td> |
| 569 | </tr> |
| 570 | |
| 571 | <tr> |
| 572 | <td><code> |
| 573 | profile stop <PROCESS> |
| 574 | </code></td> |
| 575 | <td>Stop profiler on {@code <PROCESS>}. |
| 576 | </td> |
| 577 | </tr> |
| 578 | |
| 579 | <tr> |
| 580 | <td style="white-space:nowrap"><code> |
| 581 | dumpheap [options] <PROCESS> <FILE> |
| 582 | </code></td> |
| 583 | <td>Dump the heap of {@code <PROCESS>}, write to {@code <FILE>}. <p>Options are: |
| 584 | <ul> |
| 585 | <li>{@code --user [<USER_ID>|current]}: When supplying a process name, |
| 586 | specify user of process to dump; uses current user if not specified. |
| 587 | <li>{@code -n}: Dump native heap instead of managed heap. |
| 588 | </ul> |
| 589 | </td> |
| 590 | </tr> |
| 591 | |
| 592 | <tr> |
| 593 | <td><code> |
| 594 | set-debug-app [options] <PACKAGE> |
| 595 | </code></td> |
| 596 | <td>Set application {@code <PACKAGE>} to debug. <p>Options are: |
| 597 | <ul> |
| 598 | <li>{@code -w}: Wait for debugger when application starts. |
| 599 | <li>{@code --persistent}: Retain this value. |
| 600 | </ul> |
| 601 | </td> |
| 602 | </tr> |
| 603 | |
| 604 | <tr> |
| 605 | <td><code> |
| 606 | clear-debug-app |
| 607 | </code></td> |
| 608 | <td>Clear the package previous set for debugging with {@code set-debug-app}. |
| 609 | </td> |
| 610 | </tr> |
| 611 | |
| 612 | <tr> |
| 613 | <td><code> |
| 614 | monitor [options] |
| 615 | </code></td> |
| 616 | <td>Start monitoring for crashes or ANRs. <p>Options are: |
| 617 | <ul> |
| 618 | <li>{@code --gdb}: Start gdbserv on the given port at crash/ANR. |
| 619 | </ul> |
| 620 | </td> |
| 621 | </tr> |
| 622 | |
| 623 | <tr> |
| 624 | <td><code> |
| 625 | screen-compat [on|off] <PACKAGE> |
| 626 | </code></td> |
| 627 | <td>Control <a href="{@docRoot}guide/practices/screen-compat-mode.html">screen |
| 628 | compatibility</a> mode of {@code <PACKAGE>}.</p> |
| 629 | </td> |
| 630 | </tr> |
| 631 | |
| 632 | <tr> |
| 633 | <td><code> |
| 634 | display-size [reset|<WxH>] |
| 635 | </code></td> |
| 636 | <td>Override emulator/device display size. |
| 637 | This command is helpful for testing your app across different screen sizes by mimicking a small |
| 638 | screen resolution using a device with a large screen, and vice versa. |
| 639 | <p>Example:<br><code>am display-size 1280x800</code> |
| 640 | </td> |
| 641 | </tr> |
| 642 | |
| 643 | <tr> |
| 644 | <td><code> |
| 645 | display-density <dpi> |
| 646 | </code></td> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 647 | <td>Override emulator/device display density. |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 648 | This command is helpful for testing your app across different screen densities on high-density |
| 649 | screen environment using a low density screen, and vice versa. |
| 650 | <p>Example:<br><code>am display-density 480</code> |
| 651 | </td> |
| 652 | </tr> |
| 653 | |
| 654 | <tr> |
| 655 | <td><code> |
| 656 | to-uri <INTENT> |
| 657 | </code></td> |
| 658 | <td>Print the given intent specification as a URI. <p>See the |
| 659 | <a href="#IntentSpec">Specification for <INTENT> arguments</a>. |
| 660 | </td> |
| 661 | </tr> |
| 662 | |
| 663 | <tr> |
| 664 | <td><code> |
| 665 | to-intent-uri <INTENT> |
| 666 | </code></td> |
| 667 | <td>Print the given intent specification as an {@code intent:} URI. <p>See the |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 668 | <a href="#IntentSpec">Specification for <INTENT> arguments</a>. |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 669 | </td> |
| 670 | </tr> |
| 671 | </table> |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | <h4 id="IntentSpec"> |
| 678 | <a href="" class="expandable" onclick="toggleExpandable(this,'.intents'); |
| 679 | return false">Specification for <INTENT> arguments</a></h4> |
| 680 | |
| 681 | <div class="intents" style="display:none"> |
| 682 | |
| 683 | <p>For activity manager commands that take a {@code <INTENT>} argument, you can |
| 684 | specify the intent with the following options:</p> |
| 685 | |
| 686 | <dl> |
| 687 | <dt>{@code -a <ACTION>}</dt> |
| 688 | <dd>Specify the intent action, such as "android.intent.action.VIEW". |
| 689 | You can declare this only once. |
| 690 | |
| 691 | <dt>{@code -d <DATA_URI>}</dt> |
| 692 | <dd>Specify the intent data URI, such as "content://contacts/people/1". |
| 693 | You can declare this only once. |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 694 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 695 | <dt>{@code -t <MIME_TYPE>}</dt> |
| 696 | <dd>Specify the intent MIME type, such as "image/png". |
| 697 | You can declare this only once. |
| 698 | |
| 699 | <dt>{@code -c <CATEGORY>}</dt> |
| 700 | <dd>Specify an intent category, such as "android.intent.category.APP_CONTACTS". |
| 701 | |
| 702 | <dt>{@code -n <COMPONENT>}</dt> |
Scott Main | 483d785 | 2013-01-30 15:16:10 -0800 | [diff] [blame] | 703 | <dd>Specify the component name with package name prefix to create an explicit intent, such |
| 704 | as "com.example.app/.ExampleActivity". |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 705 | |
| 706 | <dt>{@code -f <FLAGS>}</dt> |
| 707 | <dd>Add flags to the intent, as supported by {@link |
| 708 | android.content.Intent#setFlags setFlags()}. |
| 709 | |
| 710 | <dt>{@code --esn <EXTRA_KEY>}</dt> |
| 711 | <dd>Add a null extra. This option is not supported for URI intents. |
| 712 | |
| 713 | <dt>{@code -e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>}</dt> |
| 714 | <dd>Add string data as a key-value pair. |
| 715 | |
| 716 | <dt>{@code --ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>}</dt> |
| 717 | <dd>Add boolean data as a key-value pair. |
| 718 | |
| 719 | <dt>{@code --ei <EXTRA_KEY> <EXTRA_INT_VALUE>}</dt> |
| 720 | <dd>Add integer data as a key-value pair. |
| 721 | |
| 722 | <dt>{@code --el <EXTRA_KEY> <EXTRA_LONG_VALUE>}</dt> |
| 723 | <dd>Add long data as a key-value pair. |
| 724 | |
| 725 | <dt>{@code --ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE>}</dt> |
| 726 | <dd>Add float data as a key-value pair. |
| 727 | |
| 728 | <dt>{@code --eu <EXTRA_KEY> <EXTRA_URI_VALUE>}</dt> |
| 729 | <dd>Add URI data as a key-value pair. |
| 730 | |
| 731 | <dt>{@code --ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>}</dt> |
| 732 | <dd>Add a component name, which is converted and passed as |
| 733 | a {@link android.content.ComponentName} object. |
| 734 | |
| 735 | <dt>{@code --eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]}</dt> |
| 736 | <dd>Add an array of integers. |
| 737 | |
| 738 | <dt>{@code --ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]}</dt> |
| 739 | <dd>Add an array of longs. |
| 740 | |
| 741 | <dt>{@code --efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]}</dt> |
| 742 | <dd>Add an array of floats. |
| 743 | |
| 744 | <dt>{@code --grant-read-uri-permission}</dt> |
| 745 | <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION}. |
| 746 | |
| 747 | <dt>{@code --grant-write-uri-permission}</dt> |
| 748 | <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}. |
| 749 | |
| 750 | <dt>{@code --debug-log-resolution}</dt> |
| 751 | <dd>Include the flag {@link android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION}. |
| 752 | |
| 753 | <dt>{@code --exclude-stopped-packages}</dt> |
| 754 | <dd>Include the flag {@link android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES}. |
| 755 | |
| 756 | <dt>{@code --include-stopped-packages}</dt> |
| 757 | <dd>Include the flag {@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES}. |
| 758 | |
| 759 | <dt>{@code --activity-brought-to-front}</dt> |
| 760 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT}. |
| 761 | |
| 762 | <dt>{@code --activity-clear-top}</dt> |
| 763 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}. |
| 764 | |
| 765 | <dt>{@code --activity-clear-when-task-reset}</dt> |
| 766 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET}. |
| 767 | |
| 768 | <dt>{@code --activity-exclude-from-recents}</dt> |
| 769 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS}. |
| 770 | |
| 771 | <dt>{@code --activity-launched-from-history}</dt> |
| 772 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY}. |
| 773 | |
| 774 | <dt>{@code --activity-multiple-task}</dt> |
| 775 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK}. |
| 776 | |
| 777 | <dt>{@code --activity-no-animation}</dt> |
| 778 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION}. |
| 779 | |
| 780 | <dt>{@code --activity-no-history}</dt> |
| 781 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_HISTORY}. |
| 782 | |
| 783 | <dt>{@code --activity-no-user-action}</dt> |
| 784 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION}. |
| 785 | |
| 786 | <dt>{@code --activity-previous-is-top}</dt> |
| 787 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP}. |
| 788 | |
| 789 | <dt>{@code --activity-reorder-to-front}</dt> |
| 790 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT}. |
| 791 | |
| 792 | <dt>{@code --activity-reset-task-if-needed}</dt> |
| 793 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED}. |
| 794 | |
| 795 | <dt>{@code --activity-single-top}</dt> |
| 796 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}. |
| 797 | |
| 798 | <dt>{@code --activity-clear-task}</dt> |
| 799 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK}. |
| 800 | |
| 801 | <dt>{@code --activity-task-on-home}</dt> |
| 802 | <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME}. |
| 803 | |
| 804 | <dt>{@code --receiver-registered-only}</dt> |
| 805 | <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY}. |
| 806 | |
| 807 | <dt>{@code --receiver-replace-pending}</dt> |
| 808 | <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING}. |
| 809 | |
| 810 | <dt>{@code --selector}</dt> |
| 811 | <dd>Requires the use of {@code -d} and {@code -t} options to set the intent data and type. |
| 812 | |
| 813 | <dt>{@code <URI> <COMPONENT> <PACKAGE>}</dt> |
| 814 | <dd>You can directly specify a URI, package name, and component name when not qualified |
| 815 | by one of the above options. When an argument is unqualified, the tool assumes the argument |
| 816 | is a URI if it contains a ":" (colon); it assumes the argument is a component name if it |
| 817 | contains a "/" (forward-slash); otherwise it assumes the argument is a package name. |
| 818 | |
| 819 | </dl> |
| 820 | </div><!-- end 'intents' --> |
| 821 | <script> |
| 822 | $(window).hashchange( function(){ |
| 823 | if ((location.hash == "#IntentSpec") && !($("#IntentSpec a").hasClass("expanded"))) { |
| 824 | $("#IntentSpec a").click(); |
| 825 | } |
| 826 | }); |
| 827 | </script> |
| 828 | |
| 829 | |
| 830 | |
| 831 | <h3 id="pm">Using package manager (pm)</h3> |
| 832 | |
| 833 | <p>Within an adb shell, you can issue commands with the package manager ({@code pm}) tool to |
| 834 | perform actions and queries on application packages installed on the device. While in a shell, |
| 835 | the syntax is:</p> |
| 836 | <pre class="no-pretty-print"> |
| 837 | pm <command> |
| 838 | </pre> |
| 839 | |
| 840 | <p>You can also issue a package manager command directly from adb |
| 841 | without entering a remote shell. For example:</p> |
| 842 | <pre class="no-pretty-print"> |
| 843 | adb shell pm uninstall com.example.MyApp |
| 844 | </pre> |
| 845 | |
| 846 | <p class="table-caption"><strong>Table 3.</strong> Available package manager commands.</p> |
| 847 | <table> |
| 848 | <tr> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 849 | <th>Command</th> |
| 850 | <th>Description</th> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 851 | </tr> |
| 852 | |
| 853 | <tr> |
| 854 | <td><code> |
| 855 | list packages [options] <FILTER> |
| 856 | </code></td> |
| 857 | <td>Prints all packages, optionally only |
| 858 | those whose package name contains the text in {@code <FILTER>}. <p>Options: |
| 859 | <ul> |
| 860 | <li>{@code -f}: See their associated file. |
| 861 | <li>{@code -d}: Filter to only show disabled packages. |
| 862 | <li>{@code -e}: Filter to only show enabled packages. |
| 863 | <li>{@code -s}: Filter to only show system packages. |
| 864 | <li>{@code -3}: Filter to only show third party packages. |
| 865 | <li>{@code -i}: See the installer for the packages. |
| 866 | <li>{@code -u}: Also include uninstalled packages. |
| 867 | <li>{@code --user <USER_ID>}: The user space to query. |
| 868 | </ul> |
| 869 | </td> |
| 870 | </tr> |
| 871 | |
| 872 | <tr> |
| 873 | <td><code> |
| 874 | list permission-groups |
| 875 | </code></td> |
| 876 | <td>Prints all known permission groups. |
| 877 | </td> |
| 878 | </tr> |
| 879 | |
| 880 | <tr> |
| 881 | <td><code> |
| 882 | list permissions [options] <GROUP> |
| 883 | </code></td> |
Scott Main | 03c54e7 | 2013-02-05 14:05:36 -0800 | [diff] [blame] | 884 | <td>Prints all known permissions, optionally only |
| 885 | those in {@code <GROUP>}. <p>Options: |
| 886 | <ul> |
| 887 | <li>{@code -g}: Organize by group. |
| 888 | <li>{@code -f}: Print all information. |
| 889 | <li>{@code -s}: Short summary. |
| 890 | <li>{@code -d}: Only list dangerous permissions. |
| 891 | <li>{@code -u}: List only the permissions users will see. |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 892 | </ul> |
| 893 | </td> |
| 894 | </tr> |
| 895 | |
| 896 | <tr> |
| 897 | <td><code> |
| 898 | list instrumentation |
| 899 | </code></td> |
| 900 | <td>List all test packages. <p>Options: |
Scott Main | 03c54e7 | 2013-02-05 14:05:36 -0800 | [diff] [blame] | 901 | <ul> |
| 902 | <li>{@code -f}: List the APK file for the test package. |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 903 | <li>{@code <TARGET_PACKAGE>}: List test packages for only this app. |
| 904 | </ul> |
| 905 | </td> |
| 906 | </tr> |
| 907 | |
| 908 | <tr> |
| 909 | <td><code> |
| 910 | list features |
| 911 | </code></td> |
| 912 | <td>Prints all features of the system. |
| 913 | </td> |
| 914 | </tr> |
| 915 | |
| 916 | <tr> |
| 917 | <td><code> |
| 918 | list libraries |
| 919 | </code></td> |
| 920 | <td>Prints all the libraries supported by the current device. |
| 921 | </td> |
| 922 | </tr> |
| 923 | |
| 924 | <tr> |
| 925 | <td><code> |
| 926 | list users |
| 927 | </code></td> |
| 928 | <td>Prints all users on the system. |
| 929 | </td> |
| 930 | </tr> |
| 931 | |
| 932 | <tr> |
| 933 | <td><code> |
| 934 | path <PACKAGE> |
| 935 | </code></td> |
| 936 | <td>Print the path to the APK of the given {@code <PACKAGE>}. |
| 937 | </td> |
| 938 | </tr> |
| 939 | |
| 940 | <tr> |
| 941 | <td><code> |
| 942 | install [options] <PATH> |
| 943 | </code></td> |
| 944 | <td>Installs a package (specified by {@code <PATH>}) to the system. <p>Options: |
Scott Main | 03c54e7 | 2013-02-05 14:05:36 -0800 | [diff] [blame] | 945 | <ul> |
| 946 | <li>{@code -l}: Install the package with forward lock. |
| 947 | <li>{@code -r}: Reinstall an exisiting app, keeping its data. |
| 948 | <li>{@code -t}: Allow test APKs to be installed. |
| 949 | <li>{@code -i <INSTALLER_PACKAGE_NAME>}: Specify the installer package name. |
| 950 | <li>{@code -s}: Install package on the shared mass storage (such as sdcard). |
| 951 | <li>{@code -f}: Install package on the internal system memory. |
| 952 | <li>{@code -d}: Allow version code downgrade. |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 953 | </ul> |
| 954 | </td> |
| 955 | </tr> |
| 956 | |
| 957 | <tr> |
| 958 | <td><code> |
| 959 | uninstall [options] <PACKAGE> |
| 960 | </code></td> |
| 961 | <td>Removes a package from the system. <p>Options: |
Scott Main | 03c54e7 | 2013-02-05 14:05:36 -0800 | [diff] [blame] | 962 | <ul> |
| 963 | <li>{@code -k}: Keep the data and cache directories around after package removal. |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 964 | </ul> |
| 965 | </td> |
| 966 | </tr> |
| 967 | |
| 968 | <tr> |
| 969 | <td><code> |
| 970 | clear <PACKAGE> |
| 971 | </code></td> |
| 972 | <td>Deletes all data associated with a package. |
| 973 | </td> |
| 974 | </tr> |
| 975 | |
| 976 | <tr> |
| 977 | <td><code> |
| 978 | enable <PACKAGE_OR_COMPONENT> |
| 979 | </code></td> |
| 980 | <td>Enable the given package or component (written as "package/class"). |
| 981 | </td> |
| 982 | </tr> |
| 983 | |
| 984 | <tr> |
| 985 | <td><code> |
| 986 | disable <PACKAGE_OR_COMPONENT> |
| 987 | </code></td> |
| 988 | <td>Disable the given package or component (written as "package/class"). |
| 989 | </td> |
| 990 | </tr> |
| 991 | |
| 992 | <tr> |
| 993 | <td style="white-space:nowrap"><code> |
| 994 | disable-user [options] <PACKAGE_OR_COMPONENT> |
| 995 | </code></td> |
| 996 | <td><p>Options: |
| 997 | <ul> |
| 998 | <li>{@code --user <USER_ID>}: The user to disable. |
| 999 | </ul> |
| 1000 | </td> |
| 1001 | </tr> |
| 1002 | |
| 1003 | <tr> |
| 1004 | <td><code> |
| 1005 | grant <PACKAGE_PERMISSION> |
| 1006 | </code></td> |
| 1007 | <td>Grant permissions |
| 1008 | to applications. Only optional permissions the application has |
| 1009 | declared can be granted. |
| 1010 | </td> |
| 1011 | </tr> |
| 1012 | |
| 1013 | <tr> |
| 1014 | <td><code> |
| 1015 | revoke <PACKAGE_PERMISSION> |
| 1016 | </code></td> |
| 1017 | <td>Revoke permissions |
| 1018 | to applications. Only optional permissions the application has |
| 1019 | declared can be revoked. |
| 1020 | </td> |
| 1021 | </tr> |
| 1022 | |
| 1023 | <tr> |
| 1024 | <td><code> |
| 1025 | set-install-location <LOCATION> |
| 1026 | </code></td> |
| 1027 | <td>Changes the default install location. Location values: |
| 1028 | <ul> |
| 1029 | <li>{@code 0}: Auto—Let system decide the best location. |
| 1030 | <li>{@code 1}: Internal—install on internal device storage. |
| 1031 | <li>{@code 2}: External—install on external media. |
| 1032 | </ul> |
| 1033 | <p class="note"><strong>Note:</strong> This is only intended for debugging; using this can cause |
| 1034 | applications to break and other undesireable behavior.</p> |
| 1035 | </td> |
| 1036 | </tr> |
| 1037 | |
| 1038 | <tr> |
| 1039 | <td><code> |
| 1040 | get-install-location |
| 1041 | </code></td> |
| 1042 | <td>Returns the current install location. Return values: |
| 1043 | <ul> |
| 1044 | <li>{@code 0 [auto]}: Lets system decide the best location |
| 1045 | <li>{@code 1 [internal]}: Installs on internal device storage |
| 1046 | <li>{@code 2 [external]}: Installs on external media |
| 1047 | </ul> |
| 1048 | </td> |
| 1049 | </tr> |
| 1050 | |
| 1051 | <tr> |
| 1052 | <td><code> |
| 1053 | set-permission-enforced <PERMISSION> [true|false] |
| 1054 | </code></td> |
| 1055 | <td>Specifies whether the given permission should be enforced. |
| 1056 | </td> |
| 1057 | </tr> |
| 1058 | |
| 1059 | <tr> |
| 1060 | <td><code> |
| 1061 | trim-caches <DESIRED_FREE_SPACE> |
| 1062 | </code></td> |
| 1063 | <td>Trim cache files to reach the given free space. |
| 1064 | </td> |
| 1065 | </tr> |
| 1066 | |
| 1067 | <tr> |
| 1068 | <td><code> |
| 1069 | create-user <USER_NAME> |
| 1070 | </code></td> |
| 1071 | <td>Create a new user with the given {@code <USER_NAME>}, |
| 1072 | printing the new user identifier of the user. |
| 1073 | </td> |
| 1074 | </tr> |
| 1075 | |
| 1076 | <tr> |
| 1077 | <td><code> |
| 1078 | remove-user <USER_ID> |
| 1079 | </code></td> |
| 1080 | <td>Remove the user with the given {@code <USER_IDENTIFIER>}, |
| 1081 | deleting all data associated with that user |
| 1082 | </td> |
| 1083 | </tr> |
| 1084 | |
| 1085 | <tr> |
| 1086 | <td><code> |
| 1087 | get-max-users |
| 1088 | </code></td> |
| 1089 | <td>Prints the maximum number of users supported by the device. |
| 1090 | </td> |
| 1091 | </tr> |
| 1092 | |
| 1093 | </table> |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | <h3 id="sqlite">Examining sqlite3 databases from a remote shell</h3> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1102 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 1103 | <p>From an adb remote shell, you can use the |
| 1104 | <a href="http://www.sqlite.org/sqlite.html">sqlite3</a> command-line program to |
| 1105 | manage SQLite databases created by Android applications. The |
| 1106 | <code>sqlite3</code> tool includes many useful commands, such as |
| 1107 | <code>.dump</code> to print out the contents of a table and |
| 1108 | <code>.schema</code> to print the SQL CREATE statement for an existing table. |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1109 | The tool also gives you the ability to execute SQLite commands on the fly.</p> |
| 1110 | |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 1111 | <p>To use <code>sqlite3</code>, enter a remote shell on the emulator instance, as described above, |
| 1112 | then invoke the tool using the <code>sqlite3</code> command. Optionally, when invoking |
| 1113 | <code>sqlite3</code> you can specify the full path to the database you want to explore. |
| 1114 | Emulator/device instances store SQLite3 databases in the folder |
| 1115 | <code><span chatdir="1"><span chatindex="259474B4B070F261">/data/data/<em><package_name></em>/databases</span></span>/</code>. </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1116 | |
| 1117 | <p>Here's an example: </p> |
| 1118 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1119 | <pre class="no-pretty-print">adb -s emulator-5554 shell |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1120 | # sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db |
| 1121 | SQLite version 3.3.12 |
| 1122 | Enter ".help" for instructions |
| 1123 | <em>.... enter commands, then quit...</em> |
| 1124 | sqlite> .exit </pre> |
| 1125 | |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 1126 | <p>Once you've invoked <code>sqlite3</code>, you can issue <code>sqlite3</code> commands in the |
| 1127 | shell. To exit and return to the adb remote shell, use <code>exit</code> or <code>CTRL+D</code>. |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1128 | |
| 1129 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1130 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1131 | |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 1132 | <h3 id="screenrecord">Recording a device screen</h3> |
| 1133 | |
Joe Fernandez | 156cc15 | 2013-10-31 13:58:11 -0700 | [diff] [blame] | 1134 | <p>The {@code screenrecord} command is a shell utility for recording the display of devices |
| 1135 | running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 |
| 1136 | file, which you can then download and use as part of a video presentation. This utility is useful |
| 1137 | for developers who want to create promotional or training videos without using a separate |
| 1138 | recording device.</p> |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 1139 | |
| 1140 | <p>To use the {@code screenrecord} from the command line, type the following: |
| 1141 | |
| 1142 | <pre> |
| 1143 | $ adb shell screenrecord /sdcard/demo.mp4 |
| 1144 | </pre> |
| 1145 | |
| 1146 | <p>Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically |
| 1147 | at three minutes or the time limit set by {@code --time-limit}.</p> |
| 1148 | |
| 1149 | <p>Here's an example recording session, using the adb shell to record the video and the |
| 1150 | {@code pull} command to download the file from the device:<p> |
| 1151 | |
| 1152 | <pre> |
| 1153 | $ adb shell |
| 1154 | shell@ $ screenrecord --verbose /sdcard/demo.mp4 |
| 1155 | (press Ctrl-C to stop) |
| 1156 | shell@ $ exit |
| 1157 | $ adb pull /sdcard/demo.mp4 |
| 1158 | </pre> |
| 1159 | |
| 1160 | <p>The {@code screenrecord} utility can record at any supported resolution and bit rate you |
| 1161 | request, while retaining the aspect ratio of the device display. The utility records at the native |
| 1162 | display resolution and orientation by default, with a maximum length of three minutes.</p> |
| 1163 | |
| 1164 | <p>There are some known limitations of the {@code screenrecord} utility that you should be aware |
| 1165 | of when using it:</p> |
| 1166 | |
| 1167 | <ul> |
| 1168 | <li>Some devices may not be able to record at their native display resolution. |
| 1169 | If you encounter problems with screen recording, try using a lower screen resolution.</li> |
| 1170 | <li>Rotation of the screen during recording is not supported. If the screen does rotate during |
| 1171 | recording, some of the screen is cut off in the recording.</li> |
| 1172 | <li>Audio is not recorded with the video file.</li> |
| 1173 | </ul> |
| 1174 | |
| 1175 | |
| 1176 | <p class="table-caption"><strong>Table 4.</strong> {@code screenrecord} options</p> |
| 1177 | |
| 1178 | <table> |
| 1179 | <tr> |
| 1180 | <th>Options</th> |
| 1181 | <th>Description</th> |
| 1182 | </tr> |
| 1183 | |
| 1184 | <tr> |
| 1185 | <td><code>--help</code> |
| 1186 | </td> |
| 1187 | <td>Displays a usage summary.</td> |
| 1188 | </tr> |
| 1189 | |
| 1190 | <tr> |
| 1191 | <td style="white-space:nowrap"> |
| 1192 | <code>--size <WIDTHxHEIGHT></code> |
| 1193 | </td> |
| 1194 | <td>Sets the video size, for example: {@code 1280x720}. The default value is the device's main |
| 1195 | display resolution (if supported), 1280x720 if not. For best results, use a size supported |
| 1196 | by your device's Advanced Video Coding (AVC) encoder.</td> |
| 1197 | </tr> |
| 1198 | |
| 1199 | <tr> |
| 1200 | <td><code>--bit-rate <RATE></code></td> |
| 1201 | <td>Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps. |
| 1202 | You can increase the bit rate to improve video quality or lower it for smaller movie |
| 1203 | files. The following example sets the recording bit rate to 6Mbps: |
| 1204 | <pre>screenrecord --bit-rate 6000000 /sdcard/demo.mp4</pre> |
| 1205 | </td> |
| 1206 | </tr> |
| 1207 | |
| 1208 | <tr> |
| 1209 | <td><code>--time-limit <TIME></code></td> |
| 1210 | <td>Sets the maximum recording time, in seconds. The default and maximum value is 180 |
| 1211 | (3 minutes).</td> |
| 1212 | </tr> |
| 1213 | |
| 1214 | <tr> |
| 1215 | <td><code>--rotate</code></td> |
| 1216 | <td>Rotates the output 90 degrees. This feature is experimental.</td> |
| 1217 | </tr> |
| 1218 | |
| 1219 | <tr> |
| 1220 | <td><code>--verbose</code></td> |
| 1221 | <td>Displays log information on command line screen. If you do not set this option, |
| 1222 | the utility does not display any information while running.</td> |
| 1223 | </tr> |
| 1224 | |
| 1225 | </table> |
| 1226 | |
| 1227 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1228 | |
| 1229 | |
| 1230 | <h3 id="monkey">UI/Application Exerciser Monkey</h3> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1231 | |
| 1232 | <p>The Monkey is a program that runs on your emulator or device and generates pseudo-random |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 1233 | streams of user events such as clicks, touches, or gestures, as well as a number of system-level |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1234 | events. You can use the Monkey to stress-test applications that you are developing, |
| 1235 | in a random yet repeatable manner.</p> |
| 1236 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1237 | <p>The simplest way to use the monkey is with the following command, which launches your |
| 1238 | application and sends 500 pseudo-random events to it.</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1239 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1240 | <pre class="no-pretty-print">adb shell monkey -v -p your.package.name 500</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1241 | |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 1242 | <p>For more information about command options for Monkey, see the complete |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1243 | <a href="{@docRoot}tools/help/monkey.html" title="monkey">UI/Application Exerciser Monkey</a> documentation page.</p> |
| 1244 | |
| 1245 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1246 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1247 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1248 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1249 | <h3 id="othershellcommands">Other shell commands</h3> |
| 1250 | |
| 1251 | <p>For a list of all the available shell programs, use the following command:</p> |
| 1252 | |
| 1253 | <pre class="no-pretty-print">adb shell ls /system/bin</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1254 | |
| 1255 | <p>Help is available for most of the commands. </p> |
| 1256 | |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 1257 | <p>Table 5 lists some of the more common adb shell commands.</p> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1258 | |
Joe Fernandez | fbdd028 | 2013-10-30 18:26:00 -0700 | [diff] [blame] | 1259 | <p class="table-caption"><strong>Table 5.</strong> Some other adb shell commands</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1260 | <table> |
| 1261 | <tr> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 1262 | <th>Shell Command</th> |
| 1263 | <th>Description</th> |
| 1264 | <th>Comments</th> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1265 | </tr> |
| 1266 | |
| 1267 | <tr> |
| 1268 | <td><code>dumpsys</code></td> |
| 1269 | <td>Dumps system data to the screen.</td> |
Joe Fernandez | 95f6c75 | 2013-05-14 16:10:58 -0700 | [diff] [blame] | 1270 | <td rowspan=4">The <a href="{@docRoot}tools/debugging/ddms.html">Dalvik Debug Monitor Server</a> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1271 | (DDMS) tool offers integrated debug environment that you may find easier to use.</td> |
| 1272 | </tr> |
| 1273 | |
| 1274 | <tr> |
| 1275 | <td><code>dumpstate</code></td> |
| 1276 | <td>Dumps state to a file.</td> |
| 1277 | </tr> |
| 1278 | |
| 1279 | <tr> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1280 | <td><code>logcat [option]... [filter-spec]...</code></td> |
| 1281 | <td>Enables system and app logging and prints output to the screen. </td> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1282 | </tr> |
| 1283 | |
| 1284 | <tr> |
| 1285 | <td><code>dmesg</code></td> |
| 1286 | <td>Prints kernel debugging messages to the screen. </td> |
| 1287 | </tr> |
| 1288 | |
| 1289 | <tr> |
| 1290 | <td><code>start</code></td> |
| 1291 | <td>Starts (restarts) an emulator/device instance.</td> |
| 1292 | <td> </td> |
| 1293 | </tr> |
| 1294 | |
| 1295 | <tr> |
| 1296 | <td><code>stop</code></td> |
| 1297 | <td>Stops execution of an emulator/device instance.</td> |
| 1298 | <td> </td> |
| 1299 | </tr> |
| 1300 | |
| 1301 | </table> |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
Dirk Dougherty | fe57f38 | 2012-06-28 15:35:12 -0700 | [diff] [blame] | 1309 | <a name="stdout"></a> |
| 1310 | <a name="usinglogcat"></a> |
| 1311 | <a name="outputformat"></a> |
| 1312 | <a name="filteringoutput"></a> |
| 1313 | <a name="stdout"></a> |
| 1314 | <a name="logcatoptions"></a> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1315 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1316 | <h2 id="logcat">Enabling logcat logging</h2> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1317 | |
| 1318 | <p>The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the <code>logcat</code> command.</p> |
| 1319 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1320 | <p>You can use the <code>logcat</code> command to view and follow the contents of the system's log buffers. The general usage is:</p> |
| 1321 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1322 | <pre class="no-pretty-print">[adb] logcat [option] ... [filter-spec] ...</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1323 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1324 | <p>You can use the <code>logcat</code> command from your development computer or from a remote adb shell in an emulator/device instance. To view log output in your development computer, you use</p> |
| 1325 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1326 | <pre class="no-pretty-print">adb logcat</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1327 | |
| 1328 | <p>and from a remote adb shell you use</p> |
| 1329 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1330 | <pre class="no-pretty-print">logcat</pre> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1331 | |
Dirk Dougherty | fe57f38 | 2012-06-28 15:35:12 -0700 | [diff] [blame] | 1332 | <p>See <a href="{@docRoot}tools/debugging/debugging-log.html">Reading and Writing Logs</a> for complete information about logcat commend options and filter specifications.</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1333 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1334 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1335 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1336 | |
| 1337 | |
| 1338 | <h2 id="stopping">Stopping the adb server</h2> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1339 | |
| 1340 | <p>In some cases, you might need to terminate the adb server process and then restart it. For example, if adb does not respond to a command, you can terminate the server and restart it and that may resolve the problem. </p> |
| 1341 | |
Scott Main | 7467a0f | 2013-01-09 18:46:57 -0800 | [diff] [blame] | 1342 | <p>To stop the adb server, use the <code>kill-server</code> command. |
| 1343 | You can then restart the server by issuing any other adb command. </p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1344 | |
| 1345 | |
Glenn Kasten | 77c8626 | 2014-02-03 14:01:25 -0800 | [diff] [blame] | 1346 | <h2 id="wireless">Wireless usage</h2> |
| 1347 | |
| 1348 | <p> |
| 1349 | adb is usually used over USB. However, it is also possible to use over |
| 1350 | Wi-Fi, as described here. |
| 1351 | </p> |
| 1352 | |
| 1353 | <ol> |
| 1354 | |
| 1355 | <li> |
| 1356 | Connect Android device and adb host computer |
| 1357 | to a common Wi-Fi network accessible to both. |
| 1358 | We have found that not all access points |
| 1359 | are suitable; you may need to use an access point |
| 1360 | whose firewall is configured properly to support adb. |
| 1361 | </li> |
| 1362 | |
| 1363 | <li> |
| 1364 | Connect the device with USB cable to host. |
| 1365 | </li> |
| 1366 | |
| 1367 | <li> |
| 1368 | Make sure adb is running in USB mode on host. |
| 1369 | <pre> |
| 1370 | $ adb usb |
| 1371 | restarting in USB mode |
| 1372 | </pre> |
| 1373 | </li> |
| 1374 | |
| 1375 | <li> |
| 1376 | Connect to the device over USB. |
| 1377 | <pre> |
| 1378 | $ adb devices |
| 1379 | List of devices attached |
| 1380 | ######## device |
| 1381 | </pre> |
| 1382 | </li> |
| 1383 | |
| 1384 | <li> |
| 1385 | Restart host adb in tcpip mode. |
| 1386 | <pre> |
| 1387 | $ adb tcpip 5555 |
| 1388 | restarting in TCP mode port: 5555 |
| 1389 | </pre> |
| 1390 | </li> |
| 1391 | |
| 1392 | <li> |
| 1393 | Find out the IP address of the Android device: |
| 1394 | Settings -> About tablet -> Status -> IP address. |
| 1395 | Remember the IP address, of the form <code>#.#.#.#</code>. |
| 1396 | </li> |
| 1397 | |
| 1398 | <li> |
| 1399 | Connect adb host to device: |
| 1400 | <pre> |
| 1401 | $ adb connect #.#.#.# |
| 1402 | connected to #.#.#.#:5555 |
| 1403 | </pre> |
| 1404 | </li> |
| 1405 | |
| 1406 | <li> |
| 1407 | Remove USB cable from device, and confirm you can still access device: |
| 1408 | <pre> |
| 1409 | $ adb devices |
| 1410 | List of devices attached |
| 1411 | #.#.#.#:5555 device |
| 1412 | </pre> |
| 1413 | |
| 1414 | </ol> |
| 1415 | |
| 1416 | <p> |
| 1417 | You're now good to go! |
| 1418 | </p> |
| 1419 | |
| 1420 | <p> |
| 1421 | If the adb connection is ever lost: |
| 1422 | </p> |
| 1423 | |
| 1424 | <ol> |
| 1425 | |
| 1426 | <li> |
| 1427 | Make sure that your host is still connected to the same Wi-Fi network your Android device is. |
| 1428 | </li> |
| 1429 | |
| 1430 | <li> |
| 1431 | Reconnect by executing the "adb connect" step again. |
| 1432 | </li> |
| 1433 | |
| 1434 | <li> |
| 1435 | Or if that doesn't work, reset your adb host: |
| 1436 | <pre> |
| 1437 | adb kill-server |
| 1438 | </pre> |
| 1439 | and then start over from the beginning. |
| 1440 | </li> |
| 1441 | |
| 1442 | </ol> |