adb shell 命令详解
adb介绍
SDK的Tools文件夹下包含着Android模拟器操作的重要命令adb,adb的全称为(Android Debug Bridge就是调试桥的作用。通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序。借助这个工具,我们可以管理设备或手机模拟器的状态。还可以进行以下的操作:
1、快速更新设备或手机模拟器中的代码,如应用或Android 系统升级;
2、在设备上运行shell命令;
3、管理设备或手机模拟器上的预定端口;
4、在设备或手机模拟器上复制或粘贴文件;
adb在集成开发环境中的工作
adb的工作方式比较特殊采用监听Socket TCP 5554等端口的方式让IDE和Qemu通讯,默认情况下adb会daemon相关的网络端口,所以当我们运行Eclipse时adb进程就会自动运行。
1.通过adb可以轻松的执行Linux Shell命令,如adb shell dir 就是列举目录,在Linux中根目录为/而不是Windows上的C盘、D盘。
2.安装apk程序到模拟器则执行adb install android123.apk,这样名为android123的安装包就会安装到Android模拟器中,前提是android123.apk文件需要放到SDK/Tools目录下。
3.向emulator传送文件, 使用adb push android123.txt /tmp/android123.txt命令可以把SDK/Tools下的android123.txt文件传输到模拟器的/tmp/文件夹中,需要注意的是/tmp/文件夹中内容会在Android模拟器重新启动时清空。
4.从Android仿真器中回传文件到电脑
通过adb pull /tmp/android123.txt android123.txt命令就会把仿真器的tmp文件夹下android123.txt文件回传到电脑SDK/Tools目录下。
adb 常用命令大全
1. 显示系统中全部Android平台:
android list targets
2. 显示系统中全部AVD(模拟器):
android list avd
3. 创建AVD(模拟器):
android create avd --name 名称 --target 平台编号
4. 启动模拟器:
emulator -avd 名称 -sdcard ~/名称.img (-skin 1280x800)
5. 删除AVD(模拟器):
android delete avd --name 名称
6. 创建SDCard:
mksdcard 1024M ~/名称.img
7. AVD(模拟器)所在位置:
Linux(~/.android/avd) Windows(C:\Documents and Settings\Administrator\.android\avd)
8. 启动DDMS:
ddms
9. 显示当前运行的全部模拟器:
adb devices
10. 对某一模拟器执行命令:
abd -s 模拟器编号 命令
11. 安装应用程序:
adb install -r 应用程序.apk
12. 获取模拟器中的文件:
adb pull <remote> <local>
13. 向模拟器中写文件:
adb push <local> <remote>
14. 进入模拟器的shell模式:
adb shell
15. 启动SDK,文档,实例下载管理器:
android
16. 缷载apk包:
adb shell
cd data/app
rm apk包
exit
adb uninstall apk包的主包名
adb install -r apk包
17. 查看adb命令帮助信息:
adb help
18. 在命令行中查看LOG信息:
adb logcat -s 标签名
19. adb shell后面跟的命令主要来自:
源码\system\core\toolbox目录和源码\frameworks\base\cmds目录。
20. 删除系统应用:
adb remount (重新挂载系统分区,使系统分区重新可写)。
adb shell
cd system/app
rm *.apk
21. 获取管理员权限:
adb root
22. 启动Activity:
adb shell am start -n 包名/包名+类名(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据,等)。
23、发布端口:
你可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:
adb forward tcp:5555 tcp:8000
24、复制文件:
你可向一个设备或从一个设备中复制文件,
复制一个文件或目录到设备或模拟器上:
adb push <source> <destination></destination></source>
如:adb push test.txt /tmp/test.txt
从设备或模拟器上复制一个文件或目录:
adb pull <source> <destination></destination></source>
如:adb pull /addroid/lib/libwebcore.so .
25、搜索模拟器/设备的实例:
取得当前运行的模拟器/设备的实例的列表及每个实例的状态:
adb devices
26、查看bug报告:
adb bugreport
27、记录无线通讯日志:
一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录:
adb shell
logcat -b radio
28、获取设备的ID和序列号:
adb get-product
adb get-serialno
29、访问数据库SQLite3
adb shell
sqlite3
#cd system/sd/data //进入系统内指定文件夹
#ls //列表显示当前文件夹内容
#rm -r xxx //删除名字为xxx的文件夹及其里面的所有文件
#rm xxx //删除文件xxx
#rmdir xxx //删除xxx的文件夹
Android Debug Bridge version 1.0.31 -d - directs command to the only connected USB device returns an error if more than one USB device is present. -e - directs command to the only running emulator. returns an error if more than one emulator is running. -s <specific device> - directs command to the device or emulator with the given serial number or qualifier. Overrides ANDROID_SERIAL environment variable. -p <product name or path> - simple product name like 'sooner', or a relative/absolute path to a product out directory like 'out/target/product/sooner'. If -p is not specified, the ANDROID_PRODUCT_OUT environment variable is used, which must be an absolute path. devices [-l] - list all connected devices ('-l' will also list device qualifiers) connect <host>[:<port>] - connect to a device via TCP/IP Port 5555 is used by default if no port number is specified. disconnect [<host>[:<port>]] - disconnect from a TCP/IP device. Port 5555 is used by default if no port number is specified. Using this command with no additional arguments will disconnect from all connected TCP/IP devices. device commands: adb push <local> <remote> - copy file/dir to device adb pull <remote> [<local>] - copy file/dir from device adb sync [ <directory> ] - copy host->device only if changed (-l means list but don't copy) (see 'adb help all') adb shell - run remote shell interactively adb shell <command> - run remote shell command adb emu <command> - run emulator console command adb logcat [ <filter-spec> ] - View device log adb forward <local> <remote> - forward socket connections forward specs are one of: tcp:<port> localabstract:<unix domain socket name> localreserved:<unix domain socket name> localfilesystem:<unix domain socket name> dev:<character device name> jdwp:<process pid> (remote only) adb jdwp - list PIDs of processes hosting a JDWP transport adb install [-l] [-r] [-s] [--algo <algorithm name> --key <hex-encoded key> --iv <hex-encoded iv>] <file> - push this package file to the device and install it ('-l' means forward-lock the app) ('-r' means reinstall the app, keeping its data) ('-s' means install on SD card instead of internal storage) ('--algo', '--key', and '--iv' mean the file is encrypted already) adb uninstall [-k] <package> - remove this app package from the device ('-k' means keep the data and cache directories) adb bugreport - return all information from the device that should be included in a bug report. adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>] - write an archive of the device's data to <file>. If no -f option is supplied then the data is written to "backup.ab" in the current directory. (-apk|-noapk enable/disable backup of the .apks themselves in the archive; the default is noapk.) (-shared|-noshared enable/disable backup of the device's shared storage / SD card contents; the default is noshared.) (-all means to back up all installed applications) (-system|-nosystem toggles whether -all automatically includes system applications; the default is to include system apps) (<packages...> is the list of applications to be backed up. If the -all or -shared flags are passed, then the package list is optional. Applications explicitly given on the command line will be included even if -nosystem would ordinarily cause them to be omitted.) adb restore <file> - restore device contents from the <file> backup archive adb help - show this help message adb version - show version num scripting: adb wait-for-device - block until device is online adb start-server - ensure that there is a server running adb kill-server - kill the server if it is running adb get-state - prints: offline | bootloader | device adb get-serialno - prints: <serial-number> adb get-devpath - prints: <device-path> adb status-window - continuously print device status for a specified device adb remount - remounts the /system partition on the device read-write adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program adb reboot-bootloader - reboots the device into the bootloader adb root - restarts the adbd daemon with root permissions adb usb - restarts the adbd daemon listening on USB adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port networking: adb ppp <tty> [parameters] - Run PPP over USB. Note: you should not automatically start a PPP connection. <tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1 [parameters] - Eg. defaultroute debug dump local notty usepeerdns adb sync notes: adb sync [ <directory> ] <localdir> can be interpreted in several ways: - If <directory> is not specified, both /system and /data partitions will be updated. - If it is "system" or "data", only the corresponding partition is updated. environmental variables: ADB_TRACE - Print debug information. A comma separated list of the following values 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given. ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed.