ADB Commands Note
Android Debug Bridge is a pathway between your PC to your Android phone. Many commands behind the Android Studio are executed by ADB. I will go over some ADB commands so you know what it does. I write about this article because some old 👵commands of ADB are not working anymore😱. I have to try them one by one to refresh our memory.
— === Menu === —
💡 1. Requirements
📱 2. Enter the Emulator or Device
📋 3. Grab Logcat
📀 4. File IO | Backup
🏄 5. ScreenShot | URL | Image Gallery
📲 6. System Command
🕎 7. Wireless Debug Before Android 11
💡 1. Requirements …… → Menu
Please install these software:
- Android Studio 4 — It can save you a lot of work to gather the components part by part.
- AVD — Android Emulator
Android Studio
Let’s click the cube.
If both arrow-pointed spots are checked, please go to the next step.
Add path:
You need to run ADB in the Windows command-line interface. So you need to insert its command into the environment path.
C:\Users\YOUR_NAME\AppData\Local\Android\Sdk\platform-tools\
For example,
Let’s check. Open a CMD:
adb --version
📱 2. Enter the Emulator or Device …… → Menu
Android Studio
If you have a blank list, please click “Create Virtual Device”.
Find one of your AVD, click the run button.
Terminal
Windows CLI/CMD
CLI/CMD has a better view than the terminal.
ADB: List devices
adb devices
Now, you can connect your phone to this computer, too.
Run again,
Add another AVD:
C:\Users\Homan>adb devices
List of devices attached
ZY326LVCZQ device
emulator-5554 device
emulator-5556 device
ADB → “-s”: link to device
I preset system for multiple devices connection. So you’ll have this error with a shell command.
C:\Users\Homan>adb shell
adb.exe: more than one device/emulator
You need to specify the device before other instructions.
C:\Users\Homan>adb -s ZY326LVCZQ shell
ocean:/ $
Once again,
adb -s DEVICE_NAME command
When you enter the phone shell, you just use it as a Linux machine.
Linux commands:
Directory only:
ls -d *
Specific Listing:
ls -l
List File size:
ls -s
List subdirectories recursively:
ls -R
Find file:
find . -name FILE_NAME
📋 3. Grab Logcat …… → Menu
With multiple devices:
I will open and run a project with some Logcat commands in the code.
Logcat: grab all → *:V
adb -s emulator-5556 logcat *:V
I have a very long list and it is automatically updated by itself.
With color → -v color
adb -s emulator-5556 logcat *:V -v color
Logcat: search by filter: TAG:{V/D/I/W/E} *:S
V
— Verbose (lowest priority)D
— DebugI
— InfoW
— WarningE
— ErrorF
— FatalS
— Silent (highest priority, on which nothing is ever printed)
Example
Here is my Logcat tag: MLOG. I have it in permission call.
const val TAG = "MLOG"
fun lgd(s:String) = Log.d(TAG, s)// app permission
private val reqMultiplePermissions = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
permissions.entries.forEach {
lgd("mainAct: Permission: ${it.key} = ${it.value}")
if (!it.value) {
// toast
msg(this, "Permission: ${it.key} denied!", 1)
finish()
}
}
}
After I ran the app, I can grab my tab in CMD.
adb -s emulator-5556 logcat MLOG:D *:S -d
The “-d” will dump the log on screen until now.
Export(Windows/MAC/Linux): -d > your_file
I can export the log to a text file. You must use “-d” option for the export.
adb -s emulator-5556 logcat MLOG:D *:S -d > mlog.txt
Clear everything: -c
adb -s emulator-5556 logcat -c
Radio only: -b radio
adb -s emulator-5556 logcat -b radio -d
Bugreport
>adb -s emulator-5554 bugreport
📀 4. File IO | Backup …… → Menu
Copy File or Directory
I have two file in the directory:
D:\Android\test\MapDemo\app\build\outputs\apk\debug>dir
Volume in drive D is 512 Gigabyte
Volume Serial Number is BE4E-1582Directory of D:\Android\test\MapDemo\app\build\outputs\apk\debug05/19/2021 11:52 PM <DIR> .
05/19/2021 11:52 PM <DIR> ..
05/30/2021 10:26 AM 7,589,765 app-debug.apk
05/30/2021 10:26 AM 324 output-metadata.json
2 File(s) 7,590,089 bytes
2 Dir(s) 141,708,402,688 bytes free
Local → Remote: push
>adb -s emulator-5556 push output-metadata.json /mnt/sdcard/tmp
output-metadata.json: 1 file pushed, 0 skipped. 0.2 MB/s (324 bytes in 0.001s)
Let’s check:
>adb -s emulator-5556 shell ls -l /mnt/sdcard/tmp
total 392
-rw-rw---- 1 root sdcard_rw 386980 2021-06-03 15:20 mlog.txt
-rw-rw---- 1 root sdcard_rw 324 2021-05-30 10:26 output-metadata.json
👍Good!
Remote → Local: pull
>adb -s emulator-5556 pull /mnt/sdcard/tmp .
/mnt/sdcard/tmp/: 2 files pulled, 0 skipped. 8.5 MB/s (387304 bytes in 0.043s)
Let’s check:
D:\Android\test\MapDemo\app\build\outputs\apk\debug>dir
Volume in drive D is 512 Gigabyte
Volume Serial Number is BE4E-1582Directory of D:\Android\test\MapDemo\app\build\outputs\apk\debug06/03/2021 04:48 PM <DIR> .
06/03/2021 04:48 PM <DIR> ..
05/30/2021 10:26 AM 7,589,765 app-debug.apk
05/30/2021 10:26 AM 324 output-metadata.json
06/03/2021 04:48 PM <DIR> tmp
2 File(s) 7,590,089 bytes
3 Dir(s) 141,707,948,032 bytes free
👍Good!
Backup settings and apps
>adb -s emulator-5554 backup -apk -all -f backup.ab
WARNING: adb backup is deprecated and may be removed in a future release
Now unlock your device and confirm the backup operation...
It has a timeout for about a minute.
>dir *.ab
Volume in drive D is 512 Gigabyte
Volume Serial Number is BE4E-1582Directory of D:\Android\test\MapDemo\app\build\outputs\apk\debug06/03/2021 11:32 PM 6,115,506 backup.ab
1 File(s) 6,115,506 bytes
0 Dir(s) 142,200,012,800 bytes free
Backup settings, apps and shared storage
>adb -s emulator-5554 backup -apk -shared -all -f backup.ab
Size:
>dir *.ab
Volume in drive D is 512 Gigabyte
Volume Serial Number is BE4E-1582Directory of D:\Android\test\MapDemo\app\build\outputs\apk\debug06/03/2021 11:35 PM 6,854,985 backup.ab
1 File(s) 6,854,985 bytes
0 Dir(s) 142,199,263,232 bytes free
Bigger!
Backup only non-system apps
>adb -s emulator-5554 backup -apk -nosystem -all -f backup.ab
Restore a previous backup
>adb -s emulator-5554 restore backup.ab
WARNING: adb restore is deprecated and may be removed in a future release
Now unlock your device and confirm the restore operation.
🏄 5. ScreenShot | URL | Image Gallery …… → Menu
Screenshot
I am running the Map Demo.
>adb -s emulator-5554 shell screencap -p /sdcard/screencap.png
Next, you need to download the file.
>adb -s emulator-5554 pull /sdcard/screencap.png
/sdcard/screencap.png: 1 file pulled, 0 skipped. 114.6 MB/s (739708 bytes in 0.006s)
Let’s see.
Open an URL
>adb -s emulator-5554 shell am start -a android.intent.action.VIEW -d https://www.youtube.com
Starting: Intent { act=android.intent.action.VIEW dat=https://www.youtube.com/... }
Open Image Gallery
>adb -s emulator-5554 shell am start -t image/* -a android.intent.action.VIEW
Starting: Intent { act=android.intent.action.VIEW typ=image/* }
📲 6. System Command …… → Menu
Install APK → install -t filename
>adb -s emulator-5556 install -t app-debug.apk
Performing Streamed Install
Success
Reboot → reboot
>adb -s emulator-5556 reboot
Kill Server → kill-server
>adb kill-server>adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
Start Server → start-server
>adb start-server>adb devices
List of devices attached
ZY326LVCZQ device
emulator-5554 offline
emulator-5556 device
Direct call USB device: -d
>adb -d shell ls
It’s same as
>adb -s PHONE_NAME shell ls
But it is much faster.
Solve Offline Issue
D:\Android\test\MapDemo\app\build\outputs\apk\debug>adb devices
List of devices attached
ZY326LVCZQ device
emulator-5554 offline
Shut emulator-5554 down.
In AVD manager: Wipe Data
Run the same AVD again. Let’s test.
>adb devices
List of devices attached
ZY326LVCZQ device
emulator-5554 device
Get the serial number
>adb -s emulator-5554 get-serialno
emulator-5554
List TCP connectivity
>adb -s emulator-5554 shell netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 710 0 10.0.2.16:49426 142.250.138.95:https CLOSE_WAIT
tcp 1 0 10.0.2.16:45254 123.35.104.34.bc.g:http CLOSE_WAIT
tcp 1 0 10.0.2.16:42070 74.125.103.39:http CLOSE_WAIT
tcp 1 0 10.0.2.16:60892 yb-in-f101.1e100.n:http CLOSE_WAIT
tcp6 0 0 ::ffff:10.0.2.16:56838 yw-in-f188.1e100.n:5228 ESTABLISHED
tcp6 1 0 ::ffff:10.0.2.16:49522 dfw25s41-in-f14.1:https CLOSE_WAIT
tcp6 1 0 ::ffff:10.0.2.16:49524 dfw25s41-in-f14.1:https CLOSE_WAIT
...
Battery Status
>adb -s emulator-5554 shell dumpsys battery
Current Battery Service state:
AC powered: false
USB powered: false
Wireless powered: false
Max charging current: 0
Max charging voltage: 0
Charge counter: 10000
status: 4
health: 2
present: true
level: 100
scale: 100
voltage: 5000
temperature: 250
technology: Li-ion
Phone features
>adb -s emulator-5554 shell pm list features
feature:reqGlEsVersion=0x30000
feature:android.hardware.audio.output
feature:android.hardware.camera
feature:android.hardware.camera.any
feature:android.hardware.camera.ar
feature:android.hardware.camera.autofocus
feature:android.hardware.camera.capability.manual_post_processing
feature:android.hardware.camera.capability.manual_sensor
feature:android.hardware.camera.front
feature:android.hardware.camera.level.full
feature:android.hardware.faketouch
feature:android.hardware.fingerprint
feature:android.hardware.location
Service List
>adb -s emulator-5554 shell service list
Found 165 services:
0 ions: [com.android.internal.telephony.IOns]
1 gsiservice: []
2 rcs: [com.android.ims.internal.IRcsService]
3 secure_element: [android.se.omapi.ISecureElementService]
4 carrier_config: [com.android.internal.telephony.ICarrierConfigLoader]
5 phone: [com.android.internal.telephony.ITelephony]
CPU process
>adb -s emulator-5554 shell ps
USER PID PPID VSZ RSS WCHAN ADDR S NAME
root 1 0 31740 2512 0 0 S init
root 2 0 0 0 0 0 S [kthreadd]
root 4 2 0 0 0 0 I [kworker/0:0H]
root 6 2 0 0 0 0 I [mm_percpu_wq]
root 7 2 0 0 0 0 S [ksoftirqd/0]
root 8 2 0 0 0 0 I [rcu_preempt]
root 9 2 0 0 0 0 I [rcu_sched]
Screen size
>adb -s emulator-5554 shell wm size
Physical size: 1080x1920
🕎 7. Wireless Debug Before Android 11 …… → Menu
Connect phone through a USB cable + Turn on WiFi of the phone
Get WiFi IP address
>adb -d shell ip -o a | grep 192.16828: wlan0 inet 192.168.1.75/24 brd 192.168.1.255 scope global wlan0\ valid_lft forever preferred_lft forever
Or you can search the phrase “wlan0” if you are working at a free WiFi area.
Set TCP port of remote device
>adb -d tcpip 5559
restarting in TCP mode port: 5559
Connect the device with IP+port
>adb connect 192.168.1.75:5559
connected to 192.168.1.75:5559
Check result:
>adb devices
List of devices attached
ZY326LVCZQ device
192.168.1.75:5559 device
emulator-5554 device
Do you like my ADB collection?