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