第一步:上传应用
adb push <apk当前绝对路径> <apk上传路径>![]()
第二步:安装应用
adb shell pminstall-t-r<apk所在路径>第一步和第二步可以使用adb install代替
adbinstall-t-r<apk所在电脑的全路径>- adb install 会自动把 APK 从电脑传到设备临时目录,再调用 pm install,省去手动处理路径的麻烦。
- -t 允许安装测试 APK,-r 覆盖安装
第三步:查看包名
adb shell pm list package-f第四步:查看启动Activity类名
4-1:
adb 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-vtime>D: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--pid=<PID>7.19、ADB Bugreport
adb bugreport 是 Android Debug Bridge (ADB) 中一个强大的诊断工具,用于生成包含设备状态、日志和调试信息的详细报告。
# 基本用法 - 在当前目录生成报告adb bugreport# 指定输出目录adb bugreport /path/to/save/folder/# 指定文件名adb bugreport bugreport.zip# 指定设备和输出路径adb-s设备序列号 bugreport ./bugreports/7.20、adb -s
adb -s 是 ADB(Android 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 shell"pm 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-i"ActivityRecord"# Windowsadb shell dumpsys activity activities|findstr"ActivityRecord"可以配合 grep 或 findstr(Windows)来精简输出
4、 查看当前焦点所在的 Activity
adb shell dumpsys activity focuses显示当前获得焦点的 Activity 信息,通常就是用户正在交互的那个。
7.22、查看设备的IMEI数据
adb shellservicecall iphonesubinfo1
Imei号:862232050977087
7.23、查看崩溃日志信息
adb logcat-bcrash7.23.1
adb logcat -d -b crash 2>&1 | head -100adb logcat:调用Android的日志系统。
-d:转储(Dump) 并退出。表示读取当前缓冲区内的所有日志后立即结束命令,而不是像-v那样持续实时打印新日志。
-b crash:指定读取 Crash(崩溃) 缓冲区。Android系统会将应用崩溃时的详细堆栈信息专门存放在这个区域(如果不指定,默认读取main缓冲区)。
2>&1:将标准错误(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 /i"broadcast"- findstr 是 Windows 系统自带的命令行字符串查找工具,功能类似于 Linux 的 grep。
- 它会逐行读取输入,只输出包含指定搜索模式的行。
- 与 find 命令不同,findstr 支持更复杂的匹配规则(如正则表达式、忽略大小写等)。
/i 选项
- /i 表示 case-insensitive(忽略大小写)。
- 使用 /i 后,findstr 会同时匹配 broadcast、Broadcast、BROADCAST、BroadCast 等各种大小写组合。
- 如果不加 /i,则只匹配严格小写的 broadcast,可能会漏掉很多系统日志中首字母大写的 Broadcast 单词。