wy168 发表于 2023-5-5 22:40:21

使用ADB工具,操作安卓设备的基本方法


    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">现在安卓系统的设备越来越多,如何使用电脑控制和操作安卓设备呢?通常使用的是adb工具。</p>
    <h1 style="text-align: left; margin-bottom: 10px;">什么是adb工具</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB即Android Debug Bridge(安卓调试桥)tools。 它就是一个命令行窗口,用于通过电脑端与安卓设备或模拟器交互的工具。adb 命令可用于执行各种设备操作(例如安装和调试应用)。</p>
    <h1 style="text-align: left; margin-bottom: 10px;">下载ADB工具</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">下载地址:ADB Download :http://adbdownload.com/</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">有三种系统的版本,WIN、LINUX 、MAC,下载后,直接解压即可使用。</p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/b10261728ba241479f92d22de532ad31~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679818984&amp;x-signature=eMM6g9MvAdDZY%2Bh5q%2FAY1p3apsE%3D" style="width: 100%; margin-bottom: 20px;"></div>
    <h1 style="text-align: left; margin-bottom: 10px;">在设备上启用 adb 调试</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">在搭载 Android 4.2 及更高版本的设备上,ADB调试选项在”开发者选项”里,默认情况下”开发者选项”处于隐藏状态。如需显示开发者选项,请依次转到<strong style="color: blue;">设置</strong> &gt; <strong style="color: blue;">关于(手机)</strong>,然后点按 <strong style="color: blue;">build 版本号</strong>七次。返回上一个屏幕,在底部可以找到“开发者选项”。</p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/ac760caf819d42558c47471dd800a2c1~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679818984&amp;x-signature=IpEzYOIMD%2FtplZLA2fCmmhOUw1M%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">在设备上启用 adb 调试</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">不论是安卓手机还是安卓电视、安卓机顶盒,基本上都可以通过这种方法打开ADB调试选项。</p>
    <h1 style="text-align: left; margin-bottom: 10px;">通过ADB连接安卓设备</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">电脑可以通过USB数据线连接安卓设备(需要安装驱动),也可以通过网络方式连接安卓设备,我们以网络连接方式为例说明adb命令。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">1、adb连接安卓设备命令</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb connect 设备IP地址</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">实例命令:adb connect 192.168.9.100</span></p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/c095d65163b140689886d959a7564de7~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679818984&amp;x-signature=3wj45MVIYz%2FxT%2FQeOhHu9099wek%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">连接安卓设备</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">系统提示:connected to 192.168.9.100:5555,其中 5555是连接的端口号。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">2、查看已连接的安卓设备命令</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb devices</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">实例命令:adb devices</span></p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/1c9a5d27e5a04124903fe2b6624971e5~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679818984&amp;x-signature=2p8hKIYXe376yJuSqGUjJRhs4bE%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">查看已连接的安卓设备命令</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">系统会返回一个已经连接设备的列表,列出所有连接设备的IP和端口。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">3、断开已连接的安卓设备</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb disconnect &lt;设备的IP地址&gt;:5555</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">实例命令:adb disconnect 192.168.9.100:5555</span></p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/8deb51c72a934e1cadea2dd562758743~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679818984&amp;x-signature=MOFoChk5l9SlKECTx%2B0P7WmAhtc%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">断开已连接的安卓设备</p>
    </div>
    <h1 style="text-align: left; margin-bottom: 10px;">adb截图操作命令</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">adb截图可以远程截取安卓设备上显示的画面。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">adb截图命令可以先将截图保存在安卓设备上,再用pull命令将文件下载到所连接的电脑上。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb shell screencap -p 安卓设备存储路径</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">实例命令:adb shell screencap -p /sdcard/screen.png</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">将截屏的图片保存在安卓设备上的<span style="color: green;">/sdcard/</span>目录下,文件名为<span style="color: green;">screen.png。</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">使用ADB命令下载截图</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb pull /sdcard/screen.png 电脑上的目录</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">实例命令:adb pull /sdcard/screen.png D:\adb</span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">将截图文件下载到电脑D盘adb目录下。</p>
    <div style="text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/3655824bf0f24b608b7af58b3cc25b1a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;x-expires=1679818984&amp;x-signature=Aq0bJaKRULhxXdjlQQgalfEbVKI%3D" style="width: 100%; margin-bottom: 20px;">
      <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">截图效果图</p>
    </div>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">注意 :adb抓图无法抓取视频内容,抓取视频或者包含视频流窗口的页面,视频部分是黑屏的。</span></p>
    <h1 style="text-align: left; margin-bottom: 10px;">adb命令抓取日志</h1>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">1、使用adb命令抓取日志,存放到手机</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb logcat -s *:E &gt; /mmt/sdcard/1.log</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">抓取日志,保存在安卓系统的<span style="color: green;"><span style="color: green;">/mmt/sdcard/目录,文件名为1.log,抓取日志会持续抓取,想要停止抓取,可以使用ctrl+C键中断抓取。</span></span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">2、<strong style="color: blue;">使用adb命令抓取日志,存放到电脑本地磁盘</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb logcat -s *:E &gt; d:/1.log</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">抓取日志,保存在电脑D盘根目录<span style="color: green;"><span style="color: green;">,文件名为1.log。</span></span></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">3、日志级别参数</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">以上命令中:E,中的E就是日志级别参数。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">优先级是下面的字符,顺序是从低到高:</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">V 明细 verbose(最低优先级)</strong></p><strong style="color: blue;">
            <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">D 调试 debug</p>
            <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">I 信息 info</p>
            <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">W 警告 warn</p>
            <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">E 错误 error</p>
            <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">F 严重错误 fatal</p>S 无记载 silent
      </strong>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">用法实例一:</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">adb logcat 20 *:E</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">显示20条 Error 以上级别的日志。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">adb logcat *:W</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">显示全部警告warn以上级别的日志。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;">4、抓取指定APP的日志</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">ADB命令:adb logcat &lt;your package name&gt;:&lt;log level&gt; *:S</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">实例命令:adb logcat -v time -s app包名:E&gt;d:/1.log</span></p>


页: [1]
查看完整版本: 使用ADB工具,操作安卓设备的基本方法