博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to Use Android ADB Command Line Tool
阅读量:6663 次
发布时间:2019-06-25

本文共 4285 字,大约阅读时间需要 14 分钟。

(adb) is a tool that lets you manage the state of an emulator instance or Android phone. ADB is bundled with Android SDK package that can be downloaded from Android SDK download page. This tool is usefull for communicating with Android phone such as install application, copy files from/to device and perform some linux shell commands.

How to Install

Download and install (Ex:jdk-6u20-windows-i586.exe)

Download package (Ex:android-sdk_r06-windows.zip)
Extract SDK package into anywhere on your drive (Ex: D:\android-sdk-windows)
Phone Setup

In order to use ADB, you have to enable USB Debugging option in phone settings (Settings->Applications->Development)

android_usb_debugging

How to Use

  • Connect the phone to your pc/notebook usb port
  • Run Windows command line tool (cmd) and go to D:\android-sdk-windows\tool

Update!!

New Android SDK puts adb executable file on \platform-tools directory instead of tool. So the path should be D:\android-sdk-windows\platform-tools

Usefull Commands

1. Check connected phone

Syntax: adb devices

android_adb_devices

2. Login to Android shell

Syntax: adb shell

android_adb_shell

Note:

If you get ‘#’ after typing adb shell, you are already get root access on the phone, no need to type su. Otherwise if you get ‘$’ , type ‘su’ to get root access (only for rooted device).

3. Some usefull shell commands

  • ls
    List directory

Syntax: ls [path]

Example:

#ls /system/lib

  • cp
    Copy file or directory

Syntax: cp [options] source dest

Note:

To copy or delete files in Android root directories you have to change the directory access mode to ‘read and write (rw)’ using command: remount rw

Example:

#remount rw

#cp /sdcard/libsec-ril.so /system/lib

#remount ro

  • mv
    Move file or directory

Syntax: mv [options] source dest

Example:

#mv /system/lib/libsec-ril.so /sdcard/backup

  • chmod
    Change file/directory permission

Syntax: chmod [-R] mode[,mode] …. file

Example:

#chmod 0644 /system/lib/libsec-ril.so

  • rm
    Remove file or directory

Syntax: rm [options] file

Example:

#rm /system/lib/libsec-ril.so

4. Install application

You can use adb to install aplication from your local drive into phone.

Syntax: adb install appname.apk

Example:

D:\android-sdk-windows\tools\adb install D:\AnReboot.apk

android_adb_install

5. Copy files from phone to local drive

Syntax: adb pull source [destination]

Example:

D:\android-sdk-windows\tools\adb pull /sdcard/arm11-dvm.zip

D:\android-sdk-windows\tools\adb pull /sdcard/arm11-dvm.zip D:

android_adb_pull

6. Copy files from local drive to phone

Syntax: adb push source destination

Example:

D:\android-sdk-windows\tools\adb push D:\AnReboot.apk /sdcard

android_adb_push


  1. 获取序列号:

    adb get-serialno

  2. 查看连接计算机的设备:

    adb devices

  3. 重启机器:

    adb reboot

  4. 重启到bootloader,即刷机模式:

    adb reboot bootloader

  5. 重启到recovery,即恢复模式:

    adb reboot recovery

  6. 查看log:

    adb logcat

  7. 终止adb服务进程:

    adb kill-server

  8. 重启adb服务进程:

    adb start-server

  9. 获取机器MAC地址:

    adb shell cat /sys/class/net/wlan0/address

  10. 获取CPU序列号:

adb shell cat /proc/cpuinfo
  1. 安装APK:
adb install 
//比如:adb install baidu.apk
  1. 保留数据和缓存文件,重新安装apk:
adb install -r 
//比如:adb install -r baidu.apk
  1. 安装apk到sd卡:
adb install -s 
// 比如:adb install -s baidu.apk
  1. 卸载APK:
adb uninstall 
//比如:adb uninstall com.baidu.search
  1. 卸载app但保留数据和缓存文件:
adb uninstall -k 
//比如:adb uninstall -k com.baidu.search
  1. 启动应用:
adb shell am start -n 
/.
  1. 查看设备cpu和内存占用情况:
adb shell top
  1. 查看占用内存前6的app:
adb shell top -m 6
  1. 刷新一次内存信息,然后返回:
adb shell top -n 1
  1. 查询各进程内存使用情况:
adb shell procrank
  1. 杀死一个进程:
adb shell kill [pid]
  1. 查看进程列表:
adb shell ps
  1. 查看指定进程状态:
adb shell ps -x [PID]
  1. 查看后台services信息:
adb shell service list
  1. 查看当前内存占用:
adb shell cat /proc/meminfo
  1. 查看IO内存分区:
adb shell cat /proc/iomem
  1. 将system分区重新挂载为可读写分区:
adb remount
  1. 从本地复制文件到设备:
adb push 
  1. 从设备复制文件到本地:
adb pull 
  1. 列出目录下的文件和文件夹,等同于dos中的dir命令:
adb shell ls
  1. 进入文件夹,等同于dos中的cd 命令:
adb shell cd 
  1. 重命名文件:
adb shell rename path/oldfilename path/newfilename
  1. 删除system/avi.apk:
adb shell rm /system/avi.apk
  1. 删除文件夹及其下面所有文件:
adb shell rm -r 
  1. 移动文件:
adb shell mv path/file newpath/file
  1. 设置文件权限:
adb shell chmod 777 /system/fonts/DroidSansFallback.ttf
  1. 新建文件夹:
adb shell mkdir path/foldelname
  1. 查看文件内容:
adb shell cat 
  1. 查看wifi密码:
adb shell cat /data/misc/wifi/*.conf
  1. 清除log缓存:
adb logcat -c
  1. 查看bug报告:
adb bugreport
  1. 获取设备名称:
adb shell cat /system/build.prop
  1. 查看ADB帮助:
adb help
  1. 跑monkey:
adb shell monkey -v -p your.package.name 500
  1. 访问数据库SQLite3
    adb shell
    sqlite3

转载地址:http://hbcxo.baihongyu.com/

你可能感兴趣的文章
How To Install Maven On Mac OSX
查看>>
Spring事务异常回滚,捕获异常不抛出就不会回滚
查看>>
修改Ubuntu下Eclipse鼠标悬停提示背景颜色
查看>>
Java NIO:浅析I/O模型
查看>>
Android 之 ListView使用ArrayAdapter展示列表
查看>>
苦逼的程序员
查看>>
android checkbox 扩大点击区域
查看>>
如何更改Oracle字符集
查看>>
vim中的命令
查看>>
如何让电脑开机自动拨号联网
查看>>
FastDFS的安装和配置过程
查看>>
Squid学习之旅之透明代理回顾
查看>>
以操作系统方式执行和充当操作系统的一部分
查看>>
C#实现DNS解析服务
查看>>
zz: C++ 智能指针详解
查看>>
centos hadoop安装及配置
查看>>
js验证
查看>>
nodejs安装与配置淘宝镜像
查看>>
我的友情链接
查看>>
Java中将字符串转换为JsonObject
查看>>