OSDN Git Service

Regular updates
[twpd/master.git] / adb.md
1 ---
2 title: adb (Android Debug Bridge)
3 category: CLI
4 layout: 2017/sheet
5 weight: -1
6 authors:
7   - github: ZackNeyland
8 updated: 2018-03-06
9 ---
10
11 ### Device Basics
12
13 | Command                           | Description                                 |
14 | ---                               | ---                                         |
15 | `adb devices`                     | Lists connected devices                     |
16 | `adb devices -l`                  | Lists connected devices and kind            |
17 | ---                               | ---                                         |
18 | `adb root`                        | Restarts adbd with root permissions         |
19 | `adb start-server`                | Starts the adb server                       |
20 | `adb kill-server`                 | Kills the adb server                        |
21 | `adb remount`                     | Remounts file system with read/write access |
22 | `adb reboot`                      | Reboots the device                          |
23 | `adb reboot bootloader`           | Reboots the device into fastboot            |
24 | `adb disable-verity`              | Reboots the device into fastboot            |
25
26 `wait-for-device` can be specified after `adb` to ensure that the command will run once the device is connected.
27
28 `-s` can be used to send the commands to a specific device when multiple are connected.
29
30 #### Examples
31
32 ```
33 $ adb wait-for-device devices
34  List of devices attached
35  somedevice-1234 device
36  someotherdevice-1234 device
37 ```
38
39 ```
40 $ adb -s somedevice-1234 root
41 ```
42
43 ### Logcat
44
45 | Command                              | Description                            |
46 | ---                                  | ---                                    |
47 | `adb logcat`                         | Starts printing log messages to stdout |
48 | `adb logcat -g`                      | Displays current log buffer sizes      |
49 | `adb logcat -G <size>`               | Sets the buffer size (K or M)          |
50 | `adb logcat -c`                      | Clears the log buffers                 |
51 | `adb logcat *:V`                     | Enables ALL log messages (verbose)     |
52 | `adb logcat -f <filename>`           | Dumps to specified file                |
53
54 #### Examples
55 ```
56 $ adb logcat -G 16M
57 $ adb logcat *:V > output.log
58 ```
59
60 ### File Management
61
62 | Command                              | Description                       |
63 | ---                                  | ---                               |
64 | `adb push <local> <remote>` | Copies the local to the device at remote   |
65 | `adb pull <remote> <local>` | Copies the remote from the device to local |
66
67 #### Examples
68
69 ```
70 $ echo "This is a test" > test.txt
71 $ adb push  test.txt /sdcard/test.txt
72 $ adb pull /sdcard/test.txt pulledTest.txt
73 ```
74
75 ### Remote Shell
76
77 | Command                                | Description                                                           |
78 | ---                                    | ---                                                                   |
79 | `adb shell <command>`                  | Runs the specified command on device (most unix commands work here)   |
80 | `adb shell wm size`                    | Displays the current screen resolution                                |
81 | `adb shell wm size WxH`                | Sets the resolution to WxH                                            |
82 | `adb shell pm list packages`           | Lists all installed packages                                          |
83 | `adb shell pm list packages -3`        | Lists all installed 3rd-party packages                                |
84 | `adb shell monkey -p app.package.name` | Starts the specified package                                          |