1.基本语法
adb [ -d | -e | -s ]
serialNumber表示设备序列号,也可以是ip地址
如果只有一个设备/模拟器时,可以直接使用 adb 。
2.为命令指定目标设备
上述三个参数(-d -s -e)用于指定目标设备,如果有多个设备/模拟器连接,需要为命令指定目标设备,否则会无法执行命令。
- -d:指定当前唯一通过 USB 连接的 Android 设备为命令目标
- -e:指定当前唯一运行的模拟器为命令目标
- -s :指定相应 serialNumber 号的设备/模拟器为命令目标
在多个设备/模拟器连接时,大多使用-s 参数。
![9943b5fe93bf5a5b04871429b5af6449.png](https://img-blog.csdnimg.cn/img_convert/9943b5fe93bf5a5b04871429b5af6449.png)
3.查看连接设备
![b6c54c20ece33cfd790dd98485957670.png](https://img-blog.csdnimg.cn/img_convert/b6c54c20ece33cfd790dd98485957670.png)
adb devices查看连接的设备
![5a781cf40b61927640aff108313e89eb.png](https://img-blog.csdnimg.cn/img_convert/5a781cf40b61927640aff108313e89eb.png)
adb devices -l 查看,返回的信息会更多
4.安装应用
![7dc7dba6be7dc63ff9361ae46343473a.png](https://img-blog.csdnimg.cn/img_convert/7dc7dba6be7dc63ff9361ae46343473a.png)
adb install 安装应用
![850b1864c63730d7d2df38b18964f57c.png](https://img-blog.csdnimg.cn/img_convert/850b1864c63730d7d2df38b18964f57c.png)
adb install -r强制安装应用(替换存在的应用程序)
![4f8deeab6348fbb21e8c0f10ef4c589d.png](https://img-blog.csdnimg.cn/img_convert/4f8deeab6348fbb21e8c0f10ef4c589d.png)
adb install -t允许安装测试包
5.卸载应用
![354f8828a2a7f24636584a737b5cbe8f.png](https://img-blog.csdnimg.cn/img_convert/354f8828a2a7f24636584a737b5cbe8f.png)
adb uninstall 卸载应用(后面为卸载的应用的包名)
![45d2dcbcb5293163f833f6152a597ba7.png](https://img-blog.csdnimg.cn/img_convert/45d2dcbcb5293163f833f6152a597ba7.png)
pm uninstall -k保留缓存卸载应用(后面为卸载的应用的包名)
6.复制文件到电脑
![ab69911ece5390d8efcc6b9b9f931738.png](https://img-blog.csdnimg.cn/img_convert/ab69911ece5390d8efcc6b9b9f931738.png)
![7918d593006ae33c29b1d33090ab1daf.png](https://img-blog.csdnimg.cn/img_convert/7918d593006ae33c29b1d33090ab1daf.png)
adb push xxxx xxxx将电脑文件复制到手机上
7.电脑文件复制到手机
![3cfd4706724dd300fdc66a970e19d1f9.png](https://img-blog.csdnimg.cn/img_convert/3cfd4706724dd300fdc66a970e19d1f9.png)
adb shell mkdir xxxx新建文件
8.新建文件
![09c88b8b907d47acffba78d4fc4a57e6.png](https://img-blog.csdnimg.cn/img_convert/09c88b8b907d47acffba78d4fc4a57e6.png)
adb shell mkdir xxxx新建文件
9.移动文件
![42171da4274e43f864c024008282c3e5.png](https://img-blog.csdnimg.cn/img_convert/42171da4274e43f864c024008282c3e5.png)
adb shell mv xxxx xxxx移动文件
10删除
![a1f49c421f9f6f223fe21ad551e0c942.png](https://img-blog.csdnimg.cn/img_convert/a1f49c421f9f6f223fe21ad551e0c942.png)
adb shell rm xxxx删除文件
![e77b1d13b39b69c6899883ed50f82455.png](https://img-blog.csdnimg.cn/img_convert/e77b1d13b39b69c6899883ed50f82455.png)
adb shell rm -r xxxx 删除包含文件的文件夹
![ce96310b79f3e5245094e57107bc0414.png](https://img-blog.csdnimg.cn/img_convert/ce96310b79f3e5245094e57107bc0414.png)
adb shell rmdir xxxx 删除空文件夹
11.重命名
![bd3af3d3a07c2468b1673e4f4c1c5590.png](https://img-blog.csdnimg.cn/img_convert/bd3af3d3a07c2468b1673e4f4c1c5590.png)
adb shell rename xxxx xxxx重命名文件或文件夹
12打开文件
![61c6b1b09fa937d9eb5371a939fd6d0c.png](https://img-blog.csdnimg.cn/img_convert/61c6b1b09fa937d9eb5371a939fd6d0c.png)
cat打开文件,也可以在adb shell后使用
13列出目录
![0a907fc8bb686fb58be5bbb4290530b9.png](https://img-blog.csdnimg.cn/img_convert/0a907fc8bb686fb58be5bbb4290530b9.png)
ls展开文件夹中的所有目录
14返回
![7310dcab50f35b6c35dca73f16279de1.png](https://img-blog.csdnimg.cn/img_convert/7310dcab50f35b6c35dca73f16279de1.png)
cd+空格 返回根目录
![a2299a16a699fd4a0a752b65e5e32551.png](https://img-blog.csdnimg.cn/img_convert/a2299a16a699fd4a0a752b65e5e32551.png)
cd .. 返回上一层
15.清除应用数据
![fb5dd839c2bd4ff7bcd4e63ccac667e7.png](https://img-blog.csdnimg.cn/img_convert/fb5dd839c2bd4ff7bcd4e63ccac667e7.png)
16,列出设备安装应用名
abd shell pm list packages #查看当前连接设备或者虚拟机的所有包adb shell pm list packages -d #只输出禁用的包。adb shell pm list packages -e #只输出启用的包。adb shell pm list packages -s #只输出系统的包。adb shell pm list packages -i #只输出包和安装信息(安装来源)。adb shell pm list packages -u #只输出包和未安装包信息(安装来源)。adb shell pm list packages -i #只输出包和安装信息(安装来源)。adb shell pm list packages -f #输出包和包相关联的文件adb shell pm list packages -3 #输出所有第三方包。
![5de8b6e73a56afba273064ae6960f686.png](https://img-blog.csdnimg.cn/img_convert/5de8b6e73a56afba273064ae6960f686.png)
输出第三方应用
17.aapt
aapt全称:Android Asset Packaging Tool,看名称就知道他的作用是啥(Android资源打包工具),使用aapt时间先配置aapt环境(可以查看前文配置adb的文章,都是将路径添加到path中,方法相同,aapt链接: https://pan.baidu.com/s/1J4xpCTYUhWcWVFmrvgPiGA 提取码: i3yg)才能使用aapt。
aapt它的功能有很多,我们只说aapt aapt dump badging的功能。在测试中经常需要查应用的launchable-activity,sdkVersion,所以就需要用到aapt aapt dump badging,使用方法如下图。
![63138f1f588bae3d09ba4859441a90e0.png](https://img-blog.csdnimg.cn/img_convert/63138f1f588bae3d09ba4859441a90e0.png)
aapt aapt dump badging xxxx
adb命令还有很多,这里只是简单地收纳了日常使用较高的常规命令,希望对大家有所帮助。