ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

使用adb命令管理应用

使用adb命令管理应用 第一步上传应用adb push apk当前绝对路径 apk上传路径第二步安装应用adb shell pminstall-t-rapk所在路径第一步和第二步可以使用adb install代替adbinstall-t-rapk所在电脑的全路径adb install 会自动把 APK 从电脑传到设备临时目录再调用 pm install省去手动处理路径的麻烦。-t 允许安装测试 APK-r 覆盖安装第三步查看包名adb shell pm list package-f第四步查看启动Activity类名4-1adb shell4-2:dumpsys package应用包名4-3找到Category为Launcher的Activity第五步启动应用adb shell am start -n 应用包名/应用启动Activity绝对名称第六步卸载应用6.1、adb uninstall 应用包名PS:工作中可能会遇到卸载system下的应用如果使用上面的命令就行不通了可以尝试一下下面的命令adb shell pm uninstall --user 0 应用包名6.2、 卸载adb uninstall 包名6.3、 adb卸载系统应用//卸载 adb shell pm uninstall --user 0 应用包名 停用 adb shell pm disable-user 应用包名 启用 adb shell pm enable 应用包名 adb停止应用进程: adb shell am force-stop 应用包名 adb获取root权限 adb root adb重新挂载 adb remount adb查看系统版本 adb shell getprop ro.build.version.release adb查看内存使用 adb shell cat /proc/meminfo第七、其他相关使用7.1、修改IP地址adb shell ifconfig eth0 192.168.4.223 netmask 255.255.255.07.2、查看IP地址adb shell netcfg7.3、如何查看android设备属于什么架构的第一步输入 adb shell 回车第二步cat /proc/cpuinfo 回车7.4、adb命令打开手机设置页面设置主页面adb shell am start com.android.settings/com.android.settings.Settings安全adb shell am start com.android.settings/com.android.settings.SecuritySettings手机无线信息adb shell am start com.android.settings/com.android.settings.RadioInfo更多页面com.android.settings.AccessibilitySettings 辅助功能设置 com.android.settings.ActivityPicker 选择活动 com.android.settings.ApnSettings APN设置 com.android.settings.ApplicationSettings 应用程序设置 com.android.settings.BandMode 设置GSM/UMTS波段 com.android.settings.BatteryInfo 电池信息 com.android.settings.DateTimeSettings 日期和坝上旅游网时间设置7.5、adb拉取tombstones文件adb pull /data/tombstones D:\7.6、 adb拉取anr文件adb pull /data/anr/traces.txt7.7、 adb获取root权限adb root7.8、adb重新挂载adb remount7.9、 adb查看系统版本adb shell getprop ro.build.version.release7.10、adb查看内存使用adb shellcat/proc/meminfo7.11、 查看设备IP信息adb shellifconfigadb shell netcfg7.12、adb命令打开手机设置页面adb shell am start com.android.settings/com.android.settings.Settings7.13、adb打开安全adb shell am start com.android.settings/com.android.settings.SecuritySettings7.14、 adb启动系统相机并切换到拍照adb shell am start-aandroid.media.action.STILL_IMAGE_CAMERA7.15、adb关闭系统相机adb shell am force-stop com.android.camera27.16、adb查找系统相机的包名adb shell pm list packages|grepcamera7.17、 adb logcat日志输出到指定路径文件adb logcat-vtimeD:log.txt7.18、adb logcat查看指定包名日志linux环境adb logcat|grepcom.aniljing.demowindows环境gitBash:adb logcat|findstr com.aniljing.democmd可以根据应用的进程ID (PID) 来过滤日志。首先需要获取应用的PID然后过滤该PID的日志1、获取应用的进程ID adb shell pidof com.example.myapp2、然后使用--pid选项来只显示该PID的日志 adb logcat--pidPID7.19、ADB Bugreportadb bugreport 是 Android Debug Bridge (ADB) 中一个强大的诊断工具用于生成包含设备状态、日志和调试信息的详细报告。# 基本用法 - 在当前目录生成报告adb bugreport# 指定输出目录adb bugreport /path/to/save/folder/# 指定文件名adb bugreport bugreport.zip# 指定设备和输出路径adb-s设备序列号 bugreport ./bugreports/7.20、adb -sadb -s 是 ADBAndroid Debug Bridge中最重要的命令之一用于在多设备环境中指定目标设备执行操作adb-s设备标识符命令1. 安装应用# 安装APK到指定设备adb-sR58M47ZRZ4Pinstallapp.apk# 覆盖安装adb-semulator-5554install-rapp.apk# 多设备安装示例adb-sR58M47ZRZ4Pinstallapp1.apk adb-s192.168.1.100:5555installapp2.apk2. 文件操作# 推送文件adb-sR58M47ZRZ4P push local_file.txt /sdcard/# 拉取文件adb-semulator-5554 pull /sdcard/file.txt ./local/# 查看文件列表adb-sR58M47ZRZ4P shellls/sdcard/3. 日志相关# 查看日志adb-sR58M47ZRZ4P logcat# 清空日志adb-semulator-5554 logcat-c# 过滤特定应用的日志adb-sR58M47ZRZ4P logcat|grepcom.example.app4. Shell命令# 进入设备shelladb-sR58M47ZRZ4P shell# 执行单个shell命令adb-semulator-5554 shellpm list packages# 获取设备信息adb-sR58M47ZRZ4P shell getprop ro.product.model7.21、查看所有 Activity 栈1、完整信息adb shell dumpsys activity activities输出内容较多会列出所有任务栈Task、每个栈中的 Activity 记录以及当前焦点的 Activity。2、仅查看当前顶部的 Activity最常用adb shell dumpsys activitytop只显示当前位于屏幕最上方的 Activity 的详细信息包括其所在的任务栈、状态等。3、 过滤输出只关注栈中的 Activity 类名# Linux / macOSadb shell dumpsys activity activities|grep-iActivityRecord# Windowsadb shell dumpsys activity activities|findstrActivityRecord可以配合 grep 或 findstrWindows来精简输出4、 查看当前焦点所在的 Activityadb shell dumpsys activity focuses显示当前获得焦点的 Activity 信息通常就是用户正在交互的那个。7.22、查看设备的IMEI数据adb shellservicecall iphonesubinfo1Imei号8622320509770877.23、查看崩溃日志信息adb logcat-bcrash7.23.1adb logcat -d -b crash 21 | head -100adb logcat调用Android的日志系统。-d转储Dump 并退出。表示读取当前缓冲区内的所有日志后立即结束命令而不是像-v那样持续实时打印新日志。-b crash指定读取 Crash崩溃 缓冲区。Android系统会将应用崩溃时的详细堆栈信息专门存放在这个区域如果不指定默认读取main缓冲区。21将标准错误stderr重定向到标准输出stdout。这里主要用于确保如果adb连接断开或报错错误信息也能通过管道传递出去。| head -100通过管道截取前100行日志。7.23.2如果你是为了排查刚发生的闪退以下命令可能更有用添加了时间戳和详细打印# 抓取最近100条崩溃日志并带上详细的时间和进程ID adb logcat -d -b crash -v time -t 100-v time给日志加上可读的时间戳。-t 100输出最近的100行注意是小写t效果等同于 tail -100且无需依赖Linux命令。7.24、查看广播adb logcat|findstr /ibroadcastfindstr 是 Windows 系统自带的命令行字符串查找工具功能类似于 Linux 的 grep。它会逐行读取输入只输出包含指定搜索模式的行。与 find 命令不同findstr 支持更复杂的匹配规则如正则表达式、忽略大小写等。/i 选项/i 表示 case-insensitive忽略大小写。使用 /i 后findstr 会同时匹配 broadcast、Broadcast、BROADCAST、BroadCast 等各种大小写组合。如果不加 /i则只匹配严格小写的 broadcast可能会漏掉很多系统日志中首字母大写的 Broadcast 单词。
返回列表