1.abd基本使用
1.启动一个adb应用程序
adb -P <port> start-server # -P指定端口 默认是5037
1.停止adb
adb kill-server
2.查看版本
adb version
3.查看当前连接的设备
adb devices
4.进入连接设备
adb -s 127.0.0.1:62001(机器名称) shell
5.安装应用
adb -s 127.0.0.1:62001(机器名称) install app安装包名称
6.卸载应用
# 先查看包名称
adb -s 127.0.0.1:62001 shell
cd /data/app
ls
结果
cn.rongcloud.kaixinliao-1
com.douguo.recipe-1
或
adb -s 127.0.0.1:62001 shell pm list package
adb -s 127.0.0.1:62001 uninstall com.douguo.recipe(包名称)
7.通过无线网连接设备
adb connect 127.0.0.1(局域网ip):62001
8.上传文件
adb push ./yeshen.txt /sdcard
9.下拉文件
adb pull /sdcard ./yeshen.txt
10.截图
adb shell screencap -p /sdcard/text.png(文件存放路径) # 如果保存是png -p可以忽略
11.清楚应用数据和缓存
adb shell pm clear <packagename>
12.强制停止应用
adb shell am force-stop <packagename>
13.录制视频
adb shell screenrecord /sdcard/filename.mp4
2.夜神模拟器开启开发者模式
设置 < 关于平板 < 版本号
设置 < 开发者模式 < USB调试
3.统一夜神adb版本
1.替换夜神模拟器 adb.exe, AdbWinApi.dll, AdbWinUsbApi.dll这三个文件
2.夜神模拟器 nox_adb.exe文件用adb.exe替换 名字要改成nox_adb.exe
4.python执行adb
import os
# 直接执行参数中传入的命令,无法获取输出和返回值
os.system('adb shell screencap -p /sdcard/text4.png')
os.system("adb pull /sdcard/text4.png ./text4.png")
# 通过 os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出
output = os.popen('adb shell screencap -p /sdcard/text6.png')
print(output.read())
output = os.popen("adb pull /sdcard/text6.png ./text6.png")
print(output.read())
import subprocess
pr = subprocess.Popen("adb shell screencap -p /sdcard/text2.png", shell=True, stdout=subprocess.PIPE)
# pr.wait()
print(pr.stdout.read().decode("utf-8"))
pr = subprocess.Popen("adb pull /sdcard/text2.png ./text2.png", shell=True, stdout=subprocess.PIPE)
# pr.wait()
print(pr.stdout.read().decode("utf-8"))
5.adb device unauthorized
1.在终端里面输入adb kill-server
2.然后输入adb start-server
3.手机连接输入adb devices