summaryrefslogtreecommitdiffstats
path: root/docs/html/tools/help/adb.jd
blob: 47e892e2281adadf35e66fe497ea41d737bf2b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
page.title=Android Debug Bridge
parent.title=Tools
parent.link=index.html
@jd:body

<div id="qv-wrapper">
<div id="qv">
  <h2>In this document</h2>
<ol>
  <li><a href="#issuingcommands">Syntax</a></li>
  <li><a href="#commandsummary">Commands</a></li>
  <li><a href="#devicestatus">Querying for Emulator/Device Instances</a></li>
  <li><a href="#directingcommands">Directing Commands to a Specific Emulator/Device Instance</a></li>
  <li><a href="#move">Installing an Application</a></li>
  <li><a href="#forwardports">Forwarding Ports</a></li>
  <li><a href="#copyfiles">Copying Files to or from an Emulator/Device Instance</a></li>
  <li><a href="#shellcommands">Issuing Shell Commands</a>
    <ol>
      <li><a href="#am">Using activity manager (am)</a></li>
      <li><a href="#pm">Using package manager (pm)</a></li>
      <li><a href="#sqlite">Examining sqlite3 databases from a remote shell</a></li>
      <li><a href="#monkey">UI/Application Exerciser Monkey</a></li>
      <li><a href="#othershellcommands">Other shell commands</a></li>
    </ol>
  </li>
  <li><a href="#logcat">Enabling logcat logging</a></li>
  <li><a href="#stopping">Stopping the adb server</a></li>
</ol>

</div>
</div>

<p>Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an
emulator instance or connected Android-powered device. It is a client-server program that includes
three components: </p>

<ul>
  <li>A client, which runs on your development machine. You can invoke a client from a shell
by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create
adb clients. </li>
  <li>A server, which runs as a background process on your development machine. The server
manages communication between the client and the adb daemon running on an emulator or device. </li>
  <li>A daemon, which runs as a background process on each emulator or device instance. </li>
</ul>

<p>You can find the {@code adb} tool in {@code &lt;sdk&gt;/platform-tools/}.</p>

<p>When you start an adb client, the client first checks whether there is an adb server
process already running. If there isn't, it starts the server process. When the server starts,
it binds to local TCP port 5037 and listens for commands sent from adb clients&mdash;all adb
clients use port 5037 to communicate with the adb server. </p>

<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>

<p style="margin-left:2em">
Emulator 1, console: 5554<br/>
Emulator 1, adb: 5555<br>
Emulator 2, console: 5556<br>
Emulator 2, adb: 5557<br>
and so on...
</p>

<p>As shown, the emulator instance connected to adb on port 5555 is the same as the instance
whose console listens on port 5554. </p>

<p>Once the server has set up connections to all emulator instances, you can use adb commands to
access those instances. Because the server manages connections to emulator/device
instances and handles commands from multiple adb clients, you can control any emulator/device
instance from any client (or from a script).</p>




<h2 id="issuingcommands">Syntax</h2>

<p>You can issue adb commands from a command line on your development machine or from a script.
The usage is: </p>

<pre class="no-pretty-print">
adb [-d|-e|-s &lt;serialNumber&gt;] &lt;command&gt;
</pre>

<p>If there's only one emulator running or only one device connected, the adb command is
sent to that device by default. If multiple emulators are running and/or multiple devices are
attached, you need to use the <code>-d</code>, <code>-e</code>, or <code>-s</code>
option to specify the target device to which the command should be directed. </p>



<h2 id="commandsummary">Commands</h2>

<p>The table below lists all of the supported adb commands and explains their meaning and usage. </p>

<p class="table-caption"><strong>Table 1.</strong> Available adb commands</p>
<table>
<tr>
	<th>Category</th>
	<th>Command</th>
	<th>Description</th>
	<th>Comments</th>
</tr>

<tr>
<td rowspan="3">Target Device</td>
<td><code>-d</code></td>
<td>Direct an adb command to the only attached USB device.</td>
<td>Returns an error if more than one USB device is attached.</td>
</tr>

<tr>
<td><code>-e</code></td>
<td>Direct an adb command to the only running emulator instance.</td>
<td>Returns an error if more than one emulator instance is running. </td>
</tr>

<tr>
<td><code>-s&nbsp;&lt;serialNumber&gt;</code></td>
<td>Direct an adb command a specific emulator/device instance, referred to by its adb-assigned serial number (such as "emulator-5556").</td>
<td>See <a href="#directingcommands">Directing
Commands to a Specific Emulator/Device Instance</a>.</td>
</tr>

<tr>
<td rowspan="3">General</td>
<td><code>devices</code></td>
<td>Prints a list of all attached emulator/device instances.</td>
<td>See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information.</td>
</tr>

<tr>
<td><code>help</code></td>
<td>Prints a list of supported adb commands.</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>version</code></td>
<td>Prints the adb version number. </td>
<td>&nbsp;</td>
</tr>

<tr>
<td rowspan="3">Debug</td>
<td ><code>logcat&nbsp;[option] [filter-specs]</code></td>
<td>Prints log data to the screen. </td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>bugreport</code></td>
<td>Prints <code>dumpsys</code>, <code>dumpstate</code>, and <code>logcat</code> data to the screen, for the purposes of bug reporting. </td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>jdwp</code></td>
<td>Prints a list of available JDWP processes on a given device. </td>
<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>
    <code>adb forward tcp:8000 jdwp:472</code><br>
    <code>jdb -attach localhost:8000</code></p>
 </td>
</tr>

<tr>
<td rowspan=3">Data</td>
<td><code>install&nbsp;&lt;path-to-apk&gt;</code></td>
<td>Pushes an Android application (specified as a full path to an .apk file) to an emulator/device. </td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>pull&nbsp;&lt;remote&gt;&nbsp;&lt;local&gt;</code></td>
<td>Copies a specified file from an emulator/device instance to your development computer. </td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>push&nbsp;&lt;local&gt;&nbsp;&lt;remote&gt;</code></td>
<td>Copies a specified file from your development computer to an emulator/device instance. </td>
<td>&nbsp;</td>
</tr>

<tr>
<td rowspan="2">Ports and Networking</td>
<td><code>forward&nbsp;&lt;local&gt;&nbsp;&lt;remote&gt;</code></td>
<td>Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance. </td>
<td>Port specifications can use these schemes: 
<ul><li><code>tcp:&lt;portnum&gt;</code></li>
<li><code>local:&lt;UNIX domain socket name&gt;</code></li>
<li><code>dev:&lt;character device name&gt;</code></li>
<li><code>jdwp:&lt;pid&gt;</code></li></ul>
</td>
</tr>

<tr>
<td><code>ppp&nbsp;&lt;tty&gt;&nbsp;[parm]...</code></td>
<td>Run PPP over USB.
<ul>
<li><code>&lt;tty&gt;</code> &mdash; the tty for PPP stream. For example <code>dev:/dev/omap_csmi_ttyl</code>. </li>
<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>

<p>Note that you should not automatically start a PPP connection. </p></td>
<td></td>
</tr>

<tr>
<td rowspan="3">Scripting</td>
<td><code>get-serialno</code></td>
<td>Prints the adb instance serial number string.</td>
<td rowspan="2">See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information. </td>
</tr>

<tr>
<td><code>get-state</code></td>
<td>Prints the adb state of an emulator/device instance.</td>
</td>
</tr>

<tr>
<td><code>wait-for-device</code></td>
<td>Blocks execution until the device is online &mdash; that is, until the instance state is <code>device</code>.</td>
<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: 
<pre class="no-pretty-print">adb wait-for-device shell getprop</pre>

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 

<pre class="no-pretty-print">adb wait-for-device install &lt;app&gt;.apk</pre>

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>
</tr>



<tr>
<td rowspan="2">Server</td>
<td><code>start-server</code></td>
<td>Checks whether the adb server process is running and starts it, if not.</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>kill-server</code></td>
<td>Terminates the adb server process.</td>
<td>&nbsp;</td>
</tr>



<tr>
<td rowspan="2">Shell</td>
<td><code>shell</code></td>
<td>Starts a remote shell in the target emulator/device instance.</td>
<td rowspan="2">See <a href="#shellcommands">Issuing Shell Commands</a> for more information. </td>
</tr>

<tr>
<td><code>shell&nbsp;[shellCommand]</code></td>
<td>Issues a shell command in the target emulator/device instance and then exits the remote shell.</td>
</tr>

</table>










<h2 id="devicestatus">Querying for Emulator/Device Instances</h2>

<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>

	<pre class="no-pretty-print">adb devices</pre>

<p>In response, adb prints this status information for each instance:</p>

<ul>
	<li>Serial number &mdash; A string created by adb to uniquely identify an emulator/device instance by its 
        console port number. The format of the serial number is <code>&lt;type&gt;-&lt;consolePort&gt;</code>. 
        Here's an example serial number: <code>emulator-5554</code></li>
	<li>State &mdash; The connection state of the instance may be one of the following:
		<ul>
		<li><code>offline</code> &mdash; the instance is not connected to adb or is not responding.</li>
		<li><code>device</code> &mdash; the instance is now connected to the adb server. Note that this state does not 
                    imply that the Android system is fully booted and operational, since the instance connects to adb 
                    while the system is still booting. However, after boot-up, this is the normal operational state of 
                    an emulator/device instance.</li>
                <li><code>no device</code> &mdash; there is no emulator/device connected.
		</ul>
	</li>
</ul>

<p>The output for each instance is formatted like this: </p>

	<pre class="no-pretty-print">[serialNumber] [state]</pre>

<p>Here's an example showing the <code>devices</code> command and its output:</p>

	<pre class="no-pretty-print">adb devices
List of devices attached 
emulator-5554&nbsp;&nbsp;device
emulator-5556&nbsp;&nbsp;device
emulator-5558&nbsp;&nbsp;device</pre>






<h2 id="directingcommands">Directing Commands to a Specific Emulator/Device Instance</h2>

<p>If multiple emulator/device instances are running, you must specify a target instance
when issuing adb commands. To do so, use the <code>-s</code> option in the commands. The usage
for the <code>-s</code> option is:</p>

    <pre class="no-pretty-print">adb -s &lt;serialNumber&gt; &lt;command&gt; </pre>
	
<p>As shown, you specify the target instance for a command using its adb-assigned serial number.
You can use the <code>devices</code> command to obtain the serial numbers of running
emulator/device instances. For example: </p>

	<pre class="no-pretty-print">adb -s emulator-5556 install helloWorld.apk</pre>

<p>Note that, if you issue a command without specifying a target emulator/device instance
while multiple devices are available, adb generates an error.

<p>If you have multiple devices available (hardware or emulated), but only one is an emulator,
simply use the {@code -e} option to send commands to the emulator. Likewise if there's multiple
devices but only one hardware device attached, use the {@code -d} option to send commands to
the hardware device.




<h2 id="move">Installing an Application</h2>
<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>

<pre class="no-pretty-print">adb install &lt;path_to_apk&gt;</pre>

<p>For more information about how to create an .apk file that you can install on an emulator/device
instance, see <a href="{@docRoot}tools/building/index.html">Building and Running</a></p>

<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>






<h2 id="forwardports">Forwarding Ports</h2>

    <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>
<pre class="no-pretty-print">adb forward tcp:6100 tcp:7100</pre>
    <p>You can also use adb to set up forwarding to named abstract UNIX domain sockets, as illustrated here:</p>
<pre class="no-pretty-print">adb forward tcp:6100 local:logd </pre>





<h2 id="copyfiles">Copying Files to or from an Emulator/Device Instance</h2>

<p>You can use the adb commands <code>pull</code> and <code>push</code> to copy files to
and from an emulator/device instance. Unlike the <code>install</code> command,
which only copies an APK file to a specific location, the <code>pull</code> and <code>push</code>
commands let you copy arbitrary directories and files to any location in an
emulator/device instance. </p>

<p>To copy a file or directory (and its sub-directories) <em>from</em> the emulator or device, use</p>
<pre class="no-pretty-print">adb pull &lt;remote&gt; &lt;local&gt;</pre> 

<p>To copy a file or directory (and its sub-directories) <em>to</em> the emulator or device, use</p>
    <pre class="no-pretty-print">adb push &lt;local&gt; &lt;remote&gt;</pre> 

<p>In the commands, <code>&lt;local&gt;</code> and <code>&lt;remote&gt;</code> refer to the
paths to the target files/directory on your development machine (local) and on the
emulator/device instance (remote). For example: </p>
<pre class="no-pretty-print">adb push foo.txt /sdcard/foo.txt</pre>









<h2 id="shellcommands">Issuing Shell Commands</h2>

<p>Adb provides a Unix shell that you can use to run a variety of commands on an emulator 
or connected device. The command binaries are stored in the file system of the emulator or device, 
at <code>/system/bin/...</code>

<p>Two of the most common command tools are <a href="#am">activity manager</a> ({@code am}) and
<a href="#pm">package manager</a> ({@code pm}).</p>

<p>You can use the <code>shell</code> command to issue commands, with or without entering
the adb remote shell on the emulator/device. To issue a single command without entering a
remote shell, use the <code>shell</code> command like this: </p>

	<pre class="no-pretty-print">adb [-d|-e|-s &lt;serialNumber&gt;] shell &lt;shell_command&gt;</pre>
	
<p>Or enter a remote shell on an emulator/device like this:</p>

	<pre class="no-pretty-print">adb [-d|-e|-s &lt;serialNumber&gt;] shell</pre>

<p>When you are ready to exit the remote shell, press CTRL+D or type
<code>exit</code>. </p>





<h3 id="am">Using activity manager (am)</h3>

<p>Within an adb shell, you can issue commands with the activity manager ({@code am}) tool to
perform various system actions, such as start an activity, force-stop a process,
broadcast an intent, modify the device screen properties, and more. While in a shell,
the syntax is:</p>
<pre class="no-pretty-print">
am &lt;command>
</pre>

<p>You can also issue an activity manager command directly from adb
without entering a remote shell. For example:</p>
<pre class="no-pretty-print">
adb shell am start -a android.intent.action.VIEW
</pre>


<p class="table-caption"><strong>Table 2.</strong> Available activity manager commands</p>
<table>
<tr>
	<th>Command</th>
	<th>Description</th>
</tr>

<tr>
<td><code>
start [options] &lt;INTENT>
</code></td>
<td>Start an {@link android.app.Activity} specified by {@code &lt;INTENT>}. <p>See the
<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
<p>Options are:
<ul>
    <li>{@code -D}: Enable debugging.
    <li>{@code -W}: Wait for launch to complete.
    <li>{@code --start-profiler &lt;FILE>}: Start profiler and send results to {@code &lt;FILE>}.
    <li>{@code -P &lt;FILE>}: Like <code>--start-profiler</code>,
        but profiling stops when the app goes idle.
    <li>{@code -R}: Repeat the activity launch {@code &lt;COUNT>} times.  Prior to each repeat,
        the top activity will be finished.
    <li>{@code -S}: Force stop the target app before starting the activity.
    <li>{@code --opengl-trace}: Enable tracing of OpenGL functions.
    <li>{@code --user &lt;USER_ID> | current}: Specify which user to run as; if not
        specified, then run as the current user.
</ul>
</td>
</tr>

<tr>
<td><code>
startservice [options] &lt;INTENT>
</code></td>
<td>Start the {@link android.app.Service} specified by {@code &lt;INTENT>}. <p>See the
<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
<p>Options are:
<ul>
    <li>{@code --user &lt;USER_ID> | current}: Specify which user to run as; if not
        specified, then run as the current user.
</ul>
</td>
</tr>

<tr>
<td><code>
force-stop &lt;PACKAGE>
</code></td>
<td>Force stop everything associated with {@code &lt;PACKAGE>} (the app's package name).
</td>
</tr>

<tr>
<td><code>
kill  [options] &lt;PACKAGE>
</code></td>
<td> Kill all processes associated with {@code &lt;PACKAGE>}
  (the app's package name).  This command kills only
  processes that are safe to kill and that will not impact the user
  experience.
  <p>Options are:
  <ul>
      <li>{@code --user &lt;USER_ID> | all | current}: Specify user whose processes to kill;
        all users if not specified.
  </ul>
</td>
</tr>

<tr>
<td><code>
kill-all
</code></td>
<td>Kill all background processes.
</td>
</tr>

<tr>
<td><code>
broadcast [options] &lt;INTENT>
</code></td>
<td>Issue a broadcast intent. <p>See the
<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
<p>Options are:
<ul>
    <li>{@code [--user &lt;USER_ID> | all | current]}: Specify which user to send to; if not
        specified then send to all users.
</ul>
</td>
</tr>

<tr>
<td><code>
instrument [options] &lt;COMPONENT>
</code></td>
<td>Start monitoring with an {@link android.app.Instrumentation} instance.
  Typically the target {@code &lt;COMPONENT>}
  is the form {@code &lt;TEST_PACKAGE>/&lt;RUNNER_CLASS>}.  <p>Options are:
<ul>
    <li>{@code -r}: Print raw results (otherwise decode
        {@code &lt;REPORT_KEY_STREAMRESULT>}).  Use with
        {@code [-e perf true]} to generate raw output for performance measurements.

    <li>{@code -e &lt;NAME> &lt;VALUE>}: Set argument {@code &lt;NAME>} to {@code &lt;VALUE>}.
        For test runners a common form is {@code
        -e &lt;testrunner_flag> &lt;value>[,&lt;value>...]}.

    <li>{@code -p &lt;FILE>}: Write profiling data to {@code &lt;FILE>}.

    <li>{@code -w}: Wait for instrumentation to finish before returning.  Required for
        test runners.

    <li>{@code --no-window-animation}: Turn off window animations while running.
    <li>{@code --user &lt;USER_ID> | current}: Specify which user instrumentation runs in;
        current user if not specified.
</ul>

</td>
</tr>

<tr>
<td><code>
profile start &lt;PROCESS> &lt;FILE>
</code></td>
<td>Start profiler on {@code &lt;PROCESS>}, write results to {@code &lt;FILE>}.
</td>
</tr>

<tr>
<td><code>
profile stop &lt;PROCESS>
</code></td>
<td>Stop profiler on {@code &lt;PROCESS>}.
</td>
</tr>

<tr>
<td style="white-space:nowrap"><code>
dumpheap [options] &lt;PROCESS> &lt;FILE>
</code></td>
<td>Dump the heap of {@code &lt;PROCESS>}, write to {@code &lt;FILE>}. <p>Options are:
<ul>
    <li>{@code --user [&lt;USER_ID>|current]}: When supplying a process name,
        specify user of process to dump; uses current user if not specified.
    <li>{@code -n}: Dump native heap instead of managed heap.
</ul>
</td>
</tr>

<tr>
<td><code>
set-debug-app [options] &lt;PACKAGE>
</code></td>
<td>Set application {@code &lt;PACKAGE>} to debug.  <p>Options are:
<ul>
    <li>{@code -w}: Wait for debugger when application starts.
    <li>{@code --persistent}: Retain this value.
</ul>
</td>
</tr>

<tr>
<td><code>
clear-debug-app
</code></td>
<td>Clear the package previous set for debugging with {@code set-debug-app}.
</td>
</tr>

<tr>
<td><code>
monitor [options]
</code></td>
<td>Start monitoring for crashes or ANRs.  <p>Options are:
<ul>
    <li>{@code --gdb}: Start gdbserv on the given port at crash/ANR.
</ul>
</td>
</tr>

<tr>
<td><code>
screen-compat [on|off] &lt;PACKAGE>
</code></td>
<td>Control <a href="{@docRoot}guide/practices/screen-compat-mode.html">screen
compatibility</a> mode of {@code &lt;PACKAGE>}.</p>
</td>
</tr>

<tr>
<td><code>
display-size [reset|&lt;WxH>]
</code></td>
<td>Override emulator/device display size.
This command is helpful for testing your app across different screen sizes by mimicking a small
screen resolution using a device with a large screen, and vice versa.
<p>Example:<br><code>am display-size 1280x800</code>
</td>
</tr>

<tr>
<td><code>
display-density &lt;dpi>
</code></td>
<td>Override emulator/device display density. 
This command is helpful for testing your app across different screen densities on high-density
screen environment using a low density screen, and vice versa.
<p>Example:<br><code>am display-density 480</code>
</td>
</tr>

<tr>
<td><code>
to-uri &lt;INTENT>
</code></td>
<td>Print the given intent specification as a URI. <p>See the
<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
</td>
</tr>

<tr>
<td><code>
to-intent-uri &lt;INTENT>
</code></td>
<td>Print the given intent specification as an {@code intent:} URI. <p>See the
<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>. 
</td>
</tr>
</table>





<h4 id="IntentSpec">
  <a href="" class="expandable" onclick="toggleExpandable(this,'.intents');
return false">Specification for &lt;INTENT> arguments</a></h4>

<div class="intents" style="display:none">

<p>For activity manager commands that take a {@code &lt;INTENT>} argument, you can
specify the intent with the following options:</p>

<dl>
  <dt>{@code -a &lt;ACTION>}</dt>
      <dd>Specify the intent action, such as "android.intent.action.VIEW".
      You can declare this only once.

  <dt>{@code -d &lt;DATA_URI>}</dt>
      <dd>Specify the intent data URI, such as "content://contacts/people/1".
      You can declare this only once.
  
  <dt>{@code -t &lt;MIME_TYPE>}</dt>
      <dd>Specify the intent MIME type, such as "image/png".
      You can declare this only once.

  <dt>{@code -c &lt;CATEGORY>}</dt>
      <dd>Specify an intent category, such as "android.intent.category.APP_CONTACTS".

  <dt>{@code -n &lt;COMPONENT>}</dt>
      <dd>Specify the component name with package name prefix to create an explicit intent.

  <dt>{@code -f &lt;FLAGS>}</dt>
      <dd>Add flags to the intent, as supported by {@link
        android.content.Intent#setFlags setFlags()}.

  <dt>{@code --esn &lt;EXTRA_KEY>}</dt>
      <dd>Add a null extra. This option is not supported for URI intents.

  <dt>{@code -e|--es &lt;EXTRA_KEY> &lt;EXTRA_STRING_VALUE>}</dt>
      <dd>Add string data as a key-value pair.

  <dt>{@code --ez &lt;EXTRA_KEY> &lt;EXTRA_BOOLEAN_VALUE>}</dt>
      <dd>Add boolean data as a key-value pair.

  <dt>{@code --ei &lt;EXTRA_KEY> &lt;EXTRA_INT_VALUE>}</dt>
      <dd>Add integer data as a key-value pair.

  <dt>{@code --el &lt;EXTRA_KEY> &lt;EXTRA_LONG_VALUE>}</dt>
      <dd>Add long data as a key-value pair.

  <dt>{@code --ef &lt;EXTRA_KEY> &lt;EXTRA_FLOAT_VALUE>}</dt>
      <dd>Add float data as a key-value pair.

  <dt>{@code --eu &lt;EXTRA_KEY> &lt;EXTRA_URI_VALUE>}</dt>
      <dd>Add URI data as a key-value pair.

  <dt>{@code --ecn &lt;EXTRA_KEY> &lt;EXTRA_COMPONENT_NAME_VALUE>}</dt>
      <dd>Add a component name, which is converted and passed as
      a {@link android.content.ComponentName} object.

  <dt>{@code --eia &lt;EXTRA_KEY> &lt;EXTRA_INT_VALUE>[,&lt;EXTRA_INT_VALUE...]}</dt>
      <dd>Add an array of integers.

  <dt>{@code --ela &lt;EXTRA_KEY> &lt;EXTRA_LONG_VALUE>[,&lt;EXTRA_LONG_VALUE...]}</dt>
      <dd>Add an array of longs.

  <dt>{@code --efa &lt;EXTRA_KEY> &lt;EXTRA_FLOAT_VALUE>[,&lt;EXTRA_FLOAT_VALUE...]}</dt>
      <dd>Add an array of floats.

  <dt>{@code --grant-read-uri-permission}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION}.

  <dt>{@code --grant-write-uri-permission}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}.

  <dt>{@code --debug-log-resolution}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION}.

  <dt>{@code --exclude-stopped-packages}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES}.

  <dt>{@code --include-stopped-packages}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES}.

  <dt>{@code --activity-brought-to-front}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT}.

  <dt>{@code --activity-clear-top}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}.

  <dt>{@code --activity-clear-when-task-reset}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET}.

  <dt>{@code --activity-exclude-from-recents}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS}.

  <dt>{@code --activity-launched-from-history}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY}.

  <dt>{@code --activity-multiple-task}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK}.

  <dt>{@code --activity-no-animation}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION}.

  <dt>{@code --activity-no-history}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_HISTORY}.

  <dt>{@code --activity-no-user-action}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION}.

  <dt>{@code --activity-previous-is-top}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP}.

  <dt>{@code --activity-reorder-to-front}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT}.

  <dt>{@code --activity-reset-task-if-needed}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED}.

  <dt>{@code --activity-single-top}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}.

  <dt>{@code --activity-clear-task}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK}.

  <dt>{@code --activity-task-on-home}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME}.

  <dt>{@code --receiver-registered-only}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY}.

  <dt>{@code --receiver-replace-pending}</dt>
      <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING}.

  <dt>{@code --selector}</dt>
      <dd>Requires the use of {@code -d} and {@code -t} options to set the intent data and type.

  <dt>{@code &lt;URI> &lt;COMPONENT> &lt;PACKAGE>}</dt>
      <dd>You can directly specify a URI, package name, and component name when not qualified
      by one of the above options. When an argument is unqualified, the tool assumes the argument
      is a URI if it contains a ":" (colon); it assumes the argument is a component name if it
      contains a "/" (forward-slash); otherwise it assumes the argument is a package name.

</dl>
</div><!-- end 'intents' -->
<script>
  $(window).hashchange( function(){
    if ((location.hash == "#IntentSpec") && !($("#IntentSpec a").hasClass("expanded"))) {
      $("#IntentSpec a").click();
    }
  });
</script>



<h3 id="pm">Using package manager (pm)</h3>

<p>Within an adb shell, you can issue commands with the package manager ({@code pm}) tool to
perform actions and queries on application packages installed on the device. While in a shell,
the syntax is:</p>
<pre class="no-pretty-print">
pm &lt;command>
</pre>

<p>You can also issue a package manager command directly from adb
without entering a remote shell. For example:</p>
<pre class="no-pretty-print">
adb shell pm uninstall com.example.MyApp
</pre>

<p class="table-caption"><strong>Table 3.</strong> Available package manager commands.</p>
<table>
<tr>
	<th>Command</th>
	<th>Description</th>
</tr>

<tr>
<td><code>
list packages [options] &lt;FILTER>
</code></td>
<td>Prints all packages, optionally only
  those whose package name contains the text in {@code &lt;FILTER>}.  <p>Options:
<ul>
    <li>{@code -f}: See their associated file.
    <li>{@code -d}: Filter to only show disabled packages.
    <li>{@code -e}: Filter to only show enabled packages.
    <li>{@code -s}: Filter to only show system packages.
    <li>{@code -3}: Filter to only show third party packages.
    <li>{@code -i}: See the installer for the packages.
    <li>{@code -u}: Also include uninstalled packages.
    <li>{@code --user &lt;USER_ID>}: The user space to query.
</ul>
</td>
</tr>

<tr>
<td><code>
list permission-groups
</code></td>
<td>Prints all known permission groups.
</td>
</tr>

<tr>
<td><code>
list permissions [options] &lt;GROUP>
</code></td>
<td>Prints all known permissions, optionally only
  those in {@code &lt;GROUP>}.  <p>Options:
<ul>
    <li>{@code -g}: Organize by group.
    <li>{@code -f}: Print all information.
    <li>{@code -s}: Short summary.
    <li>{@code -d}: Only list dangerous permissions.
    <li>{@code -u}: List only the permissions users will see.
</ul>
</td>
</tr>

<tr>
<td><code>
list instrumentation
</code></td>
<td>List all test packages.  <p>Options:
  <ul>
    <li>{@code -f}: List the APK file for the test package.
    <li>{@code &lt;TARGET_PACKAGE>}: List test packages for only this app.
  </ul>
</td>
</tr>

<tr>
<td><code>
list features
</code></td>
<td>Prints all features of the system.
</td>
</tr>

<tr>
<td><code>
list libraries
</code></td>
<td>Prints all the libraries supported by the current device.
</td>
</tr>

<tr>
<td><code>
list users
</code></td>
<td>Prints all users on the system.
</td>
</tr>

<tr>
<td><code>
path &lt;PACKAGE>
</code></td>
<td>Print the path to the APK of the given {@code &lt;PACKAGE>}.
</td>
</tr>

<tr>
<td><code>
install [options]  &lt;PATH>
</code></td>
<td>Installs a package (specified by {@code &lt;PATH>}) to the system.  <p>Options:
  <ul>
    <li>{@code -l}: Install the package with forward lock.
    <li>{@code -r}: Reinstall an exisiting app, keeping its data.
    <li>{@code -t}: Allow test APKs to be installed.
    <li>{@code -i &lt;INSTALLER_PACKAGE_NAME>}: Specify the installer package name.
    <li>{@code -s}: Install package on the shared mass storage (such as sdcard).
    <li>{@code -f}: Install package on the internal system memory.
    <li>{@code -d}: Allow version code downgrade.
  </ul>
</td>
</tr>

<tr>
<td><code>
uninstall [options] &lt;PACKAGE>
</code></td>
<td>Removes a package from the system. <p>Options:
  <ul>
    <li>{@code -k}: Keep the data and cache directories around after package removal.
  </ul>
</td>
</tr>

<tr>
<td><code>
clear &lt;PACKAGE>
</code></td>
<td>Deletes all data associated with a package.
</td>
</tr>

<tr>
<td><code>
enable &lt;PACKAGE_OR_COMPONENT>
</code></td>
<td>Enable the given package or component (written as "package/class").
</td>
</tr>

<tr>
<td><code>
disable &lt;PACKAGE_OR_COMPONENT>
</code></td>
<td>Disable the given package or component (written as "package/class").
</td>
</tr>

<tr>
<td style="white-space:nowrap"><code>
disable-user [options] &lt;PACKAGE_OR_COMPONENT>
</code></td>
<td><p>Options:
  <ul>
    <li>{@code --user &lt;USER_ID>}: The user to disable.
  </ul>
</td>
</tr>

<tr>
<td><code>
grant &lt;PACKAGE_PERMISSION>
</code></td>
<td>Grant permissions
  to applications.  Only optional permissions the application has
  declared can be granted.
</td>
</tr>

<tr>
<td><code>
revoke &lt;PACKAGE_PERMISSION>
</code></td>
<td>Revoke permissions
  to applications.  Only optional permissions the application has
  declared can be revoked.
</td>
</tr>

<tr>
<td><code>
set-install-location &lt;LOCATION>
</code></td>
<td>Changes the default install location. Location values:
<ul>
    <li>{@code 0}: Auto&mdash;Let system decide the best location.
    <li>{@code 1}: Internal&mdash;install on internal device storage.
    <li>{@code 2}: External&mdash;install on external media.
</ul>
<p class="note"><strong>Note:</strong> This is only intended for debugging; using this can cause
  applications to break and other undesireable behavior.</p>
</td>
</tr>

<tr>
<td><code>
get-install-location
</code></td>
<td>Returns the current install location. Return values:
<ul>
  <li>{@code 0 [auto]}: Lets system decide the best location
  <li>{@code 1 [internal]}: Installs on internal device storage
  <li>{@code 2 [external]}: Installs on external media
</ul>
</td>
</tr>

<tr>
<td><code>
set-permission-enforced &lt;PERMISSION> [true|false]
</code></td>
<td>Specifies whether the given permission should be enforced.
</td>
</tr>

<tr>
<td><code>
trim-caches &lt;DESIRED_FREE_SPACE>
</code></td>
<td>Trim cache files to reach the given free space.
</td>
</tr>

<tr>
<td><code>
create-user &lt;USER_NAME>
</code></td>
<td>Create a new user with the given {@code &lt;USER_NAME>},
  printing the new user identifier of the user.
</td>
</tr>

<tr>
<td><code>
remove-user &lt;USER_ID>
</code></td>
<td>Remove the user with the given {@code &lt;USER_IDENTIFIER>},
  deleting all data associated with that user
</td>
</tr>

<tr>
<td><code>
get-max-users
</code></td>
<td>Prints the maximum number of users supported by the device.
</td>
</tr>

</table>







<h3 id="sqlite">Examining sqlite3 databases from a remote shell</h3>

<p>From an adb remote shell, you can use the 
<a href="http://www.sqlite.org/sqlite.html">sqlite3</a> command-line program to 
manage SQLite databases created by Android applications. The 
<code>sqlite3</code> tool includes many useful commands, such as 
<code>.dump</code> to print out the contents of a table and 
<code>.schema</code> to print the SQL CREATE statement for an existing table. 
The tool also gives you the ability to execute SQLite commands on the fly.</p>

<p>To use <code>sqlite3</code>, enter a remote shell on the emulator instance, as described above, then invoke the tool using the <code>sqlite3</code> command. Optionally, when invoking <code>sqlite3</code> you can specify the full path to the database you want to explore. Emulator/device instances store SQLite3 databases in the folder <code><span chatdir="1"><span chatindex="259474B4B070F261">/data/data/<em>&lt;package_name&gt;</em>/databases</span></span>/</code>. </p>

<p>Here's an example: </p>

<pre class="no-pretty-print">adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter &quot;.help&quot; for instructions
<em>.... enter commands, then quit...</em>
sqlite&gt; .exit </pre>

<p>Once you've invoked <code>sqlite3</code>, you can issue <code>sqlite3</code> commands in the shell. To exit and return to the adb remote shell, use <code>exit</code> or <code>CTRL+D</code>.






<h3 id="monkey">UI/Application Exerciser Monkey</h3>

<p>The Monkey is a program that runs on your emulator or device and generates pseudo-random
streams of user events such as clicks, touches, or gestures, as well as a number of system-level 
events.  You can use the Monkey to stress-test applications that you are developing,
in a random yet repeatable manner.</p>

<p>The simplest way to use the monkey is with the following command, which launches your
application and sends 500 pseudo-random events to it.</p>

<pre class="no-pretty-print">adb shell monkey -v -p your.package.name 500</pre>

<p>For more information about command options for Monkey, see the complete 
<a href="{@docRoot}tools/help/monkey.html" title="monkey">UI/Application Exerciser Monkey</a> documentation page.</p>





<h3 id="othershellcommands">Other shell commands</h3>

<p>For a list of all the available shell programs, use the following command:</p>

<pre class="no-pretty-print">adb shell ls /system/bin</pre>

<p>Help is available for most of the commands. </p>

<p>Table 4 lists some of the more common adb shell commands.</p>

<p class="table-caption"><strong>Table 4.</strong> Some other adb shell commands</p>
<table>
<tr>
	<th>Shell Command</th>
	<th>Description</th>
	<th>Comments</th>
</tr>

<tr>
<td><code>dumpsys</code></td>
<td>Dumps system data to the screen.</td>
<td rowspan=4">The <a href="{@docRoot}tools/debugging/ddms.html">Dalvik Debug Monitor Server</a> 
(DDMS) tool offers integrated debug environment that you may find easier to use.</td>
</tr>

<tr>
<td><code>dumpstate</code></td>
<td>Dumps state to a file.</td>
</tr>

<tr>
<td><code>logcat&nbsp;[option]...&nbsp;[filter-spec]...</code></td>
<td>Enables system and app logging and prints output to the screen. </td>
</tr>

<tr>
<td><code>dmesg</code></td>
<td>Prints kernel debugging messages to the screen. </td>
</tr>

<tr>
<td><code>start</code></td>
<td>Starts (restarts) an emulator/device instance.</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><code>stop</code></td>
<td>Stops execution of an emulator/device instance.</td>
<td>&nbsp;</td>
</tr>

</table>







<a name="stdout"></a>
<a name="usinglogcat"></a>
<a name="outputformat"></a>
<a name="filteringoutput"></a>
<a name="stdout"></a>
<a name="logcatoptions"></a>

<h2 id="logcat">Enabling logcat logging</h2>

<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>

<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>

<pre class="no-pretty-print">[adb] logcat [option] ... [filter-spec] ...</pre>

<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>

<pre class="no-pretty-print">adb logcat</pre>

<p>and from a remote adb shell you use</p>

<pre class="no-pretty-print">logcat</pre>

<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>





<h2 id="stopping">Stopping the adb server</h2>

<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>

<p>To stop the adb server, use the <code>kill-server</code> command.
You can then restart the server by issuing any other adb command. </p>