学习目标:学习ADB的基本语法
1.adb version
adb version用于查看adb 版本
C:\Users\le>adb version
Android Debug Bridge version 1.0.39
Version 0.0.1-4500957
Installed as C:\Users\le\Desktop\Maohuan\platform-tools-latest-windows\platform-tools\adb.exe``
2.adb devices
adb devices用于查看adb所接的设备的代号
C:\Users\le>adb devices
List of devices attached
emulator-5554 device
这里用的是模拟器练习,所以设备代号为emulator-5554,正常来讲,未改变的设备号为一串无序的字母和数字的组合
3.获取手机序列号
adb get-serialno
C:\Users\le>adb get-serialno
emulator-5554
get-serialno就是提供了提取devices中的设备序列号的简易方式,不用去写一些代码来选择到手机序列号
4.查看手机设备型号
adb shell getprop ro.product.model
C:\Users\le>adb shell getprop ro.product.model
LIO-AN00
这里使用模拟器会显示LIO-AN00模拟器的设备型号,如果是手机的话应该会显示厂商的内容
5.查看手机分辨率
adb shell wm size
C:\Users\le>adb shell wm size
Physical size: 1080x1920
显示手机分辨率(模拟器设定为1080x1920)
6.获取手机的mac地址
adb shell cat /sys/class/net/wlan0/address
C:\Users\le>adb shell cat /sys/class/net/wlan0/address
/system/bin/sh: cat: /sys/class/net/wlan0/address: No such file or directory
模拟器没有相应的address文件cat出地址,因此显示No such file or directory。
如果是真实的手机应该会是一串由‘:’分隔的16进制地址
PS:cat命令在查看一些文件信息时会用到,非常有用
7.查看日志、
adb shell logcat
C:\Users\le>adb shell logcat >log.txt
adb shell logcat输出速度太快太多,一般会写成这样来录log,log会写到txt文件中去。
或者直接写成adb shell logcat |grep 'XXXX’来从log中搜索一些关键字
8.查看电池信息
adb shell dumpsys battery
C:\Users\le\Desktop>adb shell dumpsys battery
Current Battery Service state:
AC powered: true
USB powered: false
Wireless powered: false
Max charging current: 0
Max charging voltage: 0
Charge counter: 0
status: 1
health: 1
present: true
level: 100
scale: 100
voltage: 3905
temperature: 299
technology: Unknown
会输出一些关于battery(电池)的系统信息,比如充电状态,电池状态等
9.查看进程
adb shell ps
C:\Users\le\Desktop>adb shell ps
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 7172 1780 0 c7fffc10 S /init
root 2 0 0 0 0 00000000 S kthreadd
root 3 2 0 0 0 00000000 S ksoftirqd/0
root 4 2 0 0 0 00000000 S kworker/0:0
root 5 2 0 0 0 00000000 S kworker/0:0H
root 7 2 0 0 0 00000000 S rcu_sched
root 8 2 0 0 0 00000000 S rcu_bh
root 9 2 0 0 0 00000000 S migration/0
root 10 2 0 0 0 00000000 S migration/1
root 11 2 0 0 0 00000000 S ksoftirqd/1
root 13 2 0 0 0 00000000 S kworker/1:0H
root 14 2 0 0 0 00000000 S khelper
...
ps用于查看系统进程,一般用于搜索进程PID,PPID和NAME,然后提取出来
10.查看CPU使用情况
adb shell top
C:\Users\le\Desktop>adb shell top
[?25l[0m[H[J[s[999C[999B[6n[uTasks: 108 total, 1 running, 105 sleeping, 0 stopped, 1 zombie
Mem: 3564392k total, 1894312k used, 1670080k free, 3960k buffers
Swap: 0k total, 0k used, 0k free, 189976k cached
200%cpu 32%user 0%nice 16%sys 152%idle 0%iow 0%irq 0%sirq 0%host
[7m PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS [0m
2055 u0_a34 10 -10 2.7G 1.3G 69M S 44.0 38.5 32:52.34 com.bilibili.fatego
1075 root -2 -8 48M 2.2M 1.0M S 8.0 0.0 1:46.49 surfaceflinger
4258 root 20 0 6.0M 2.8M 2.4M R 4.0 0.0 0:00.00 top
3814 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:0]
3533 u0_a7 20 0 1.0G 48M 32M S 0.0 1.3 0:00.03 com.android.mtp
3514 u0_a9 20 0 1.0G 46M 30M S 0.0 1.3 0:00.02 com.android.external
3497 u0_a6 20 0 1.0G 46M 30M S 0.0 1.3 0:00.05 com.android.document
3481 u0_a5 20 0 1.0G 45M 29M S 0.0 1.2 0:00.09 com.android.defconta
3249 root 20 0 0 0 0 S 0.0 0.0 0:00.02 [kworker/u4:0]
2839 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:2]
查看正在占用CPU的进程,你可以打开一个进程,然后找出这个进程的占用多少,和这个进程的进程名等相关信息
11.安装手机APK
adb install [APK路径]
C:\Users\le\Desktop>adb install C:\Users\le\Desktop\XXXX\XXXXX\XXXX.APK
目前手上没有能够install的.apk文件,路径可以直接拖拽到cmd窗口下获得
多个设备安装apk
adb -s [设备号] install [apk文件的路径]
C:\Users\le\Desktop>adb -s emulator-5554 isntall C:\Users\le\Desktop\XXXX\XXXXX\XXXX.APK
设备号(emulator-5554)可以通过adb devices和adb get-serialno来获得
如果apk已经存在,需要覆盖安装
adb install -r C:\Users\le\Desktop\XXXX\XXXXX\XXXX.APK
12.卸载APK
adb uninstall 文件路径
注:我不知道怎么获取文件路径,一般来讲用包名来卸载APK比较方便查找,一般用第三方包查找可以快速找到
adb uninstall 包名
C:\Users\le\Desktop>adb uninstall com.qihoo.browser
Success
删除com.qihoo.browser包名所代表的APK,也就是360浏览器
卸载但是保留数据
adb uninstall -k 包名
13.查看手机上安装的所有包名
adb shell pm list packages
查找,删除,一气呵成,是adb中的豪杰
C:\Users\le\Desktop>adb shell pm list packages
package:com.android.cts.priv.ctsshim
package:com.android.providers.telephony
package:com.android.providers.calendar
package:com.android.providers.media
package:com.android.documentsui
package:com.android.externalstorage
package:com.android.htmlviewer
package:com.android.mms.service
package:com.android.providers.downloads
package:com.android.browser
package:com.android.inputmethod.pinyin
package:com.android.defcontainer
package:com.android.providers.downloads.ui
package:com.android.pacprocessor
package:com.android.certinstaller
package:com.android.carrierconfig
package:android
package:com.android.contacts
package:com.android.mtp
package:com.android.launcher3
package:com.android.statementservice
package:com.android.providers.settings
package:com.android.sharedstoragebackup
package:com.android.printspooler
package:com.android.webview
package:com.bilibili.fatego
package:android.ext.shared
package:com.android.server.telecom
package:com.android.keychain
package:com.android.gallery3d
package:com.android.flysilkworm
package:android.ext.services
package:com.android.packageinstaller
package:com.android.basicsmsreceiver
package:com.android.proxyhandler
package:com.cyanogenmod.filemanager
package:com.android.managedprovisioning
package:com.android.googleinstaller
package:com.android.storagemanager
package:com.android.bookmarkprovider
package:com.android.settings
package:com.android.cts.ctsshim
package:com.android.vpndialogs
package:com.android.phone
package:com.android.shell
package:com.android.wallpaperbackup
package:com.android.providers.blockednumber
package:com.android.providers.userdictionary
package:com.android.location.fused
package:com.android.systemui
package:com.android.providers.contacts
package:tv.danmaku.bili
package:com.android.captiveportallogin
package:com.android.coreservice
约束查找方向
查找第三方包名
adb shell pm list packages -3
C:\Users\le\Desktop>adb shell pm list packages -3
package:com.bilibili.fatego
package:tv.danmaku.bili
查找系统包名
C:\Users\le\Desktop>adb shell pm list packages -s
package:com.android.cts.priv.ctsshim
package:com.android.providers.telephony
package:com.android.providers.calendar
package:com.android.providers.media
package:com.android.documentsui
package:com.android.externalstorage
package:com.android.htmlviewer
package:com.android.mms.service
package:com.android.providers.downloads
package:com.android.browser
package:com.android.inputmethod.pinyin
package:com.android.defcontainer
package:com.android.providers.downloads.ui
package:com.android.pacprocessor
package:com.android.certinstaller
package:com.android.carrierconfig
package:android
package:com.android.contacts
package:com.android.mtp
package:com.android.launcher3
package:com.android.statementservice
package:com.android.providers.settings
package:com.android.sharedstoragebackup
package:com.android.printspooler
package:com.android.webview
package:android.ext.shared
package:com.android.server.telecom
package:com.android.keychain
package:com.android.gallery3d
package:com.android.flysilkworm
package:android.ext.services
package:com.android.packageinstaller
package:com.android.basicsmsreceiver
package:com.android.proxyhandler
package:com.cyanogenmod.filemanager
package:com.android.managedprovisioning
package:com.android.googleinstaller
package:com.android.storagemanager
package:com.android.bookmarkprovider
package:com.android.settings
package:com.android.cts.ctsshim
package:com.android.vpndialogs
package:com.android.phone
package:com.android.shell
package:com.android.wallpaperbackup
package:com.android.providers.blockednumber
package:com.android.providers.userdictionary
package:com.android.location.fused
package:com.android.systemui
package:com.android.providers.contacts
package:com.android.captiveportallogin
package:com.android.coreservice
参考资料:https://blog.csdn.net/weixin_41635750/article/details/108297319?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164156636516780271529033%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=164156636516780271529033&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-108297319.first_rank_v2_pc_rank_v29&utm_term=adb%E5%91%BD%E4%BB%A4&spm=1018.2226.3001.4187