假设android SDK(Software Development Kit, 软件开发工具包)安装路径为~。
android命令
android命令在~/sdk/tools目录下。
打开命令行窗口,切换到~/sdk/tools目录下并运行android --help命令:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\tools>android --help
输出了如下信息:
- sdk : Displays the SDK Manager window.
- avd : Displays the AVD Manager window.
- list : Lists existing targets or virtual devices.
- list avd : Lists existing Android Virtual Devices.
- list target : Lists existing targets.
- list sdk : Lists remote SDK repository.
- create avd : Creates a new Android Virtual Device.
- move avd : Moves or renames an Android Virtual Device.
- delete avd : Deletes an Android Virtual Device.
- update avd : Updates an Android Virtual Device to match the folders
of a new SDK.
- create project : Creates a new Android project.
- update project : Updates an Android project (must already have an
AndroidManifest.xml).
- create test-project : Creates a new Android project for a test package.
- update test-project : Updates the Android project for a test package (must
already have an AndroidManifest.xml).
- create lib-project : Creates a new Android library project.
- update lib-project : Updates an Android library project (must already have
an AndroidManifest.xml).
- create uitest-project: Creates a new UI test project.
- update adb : Updates adb to support the USB devices declared in the
SDK add-ons.
- update sdk : Updates the SDK by suggesting new platforms to install
if available.
我们可以看到,android命令可以用于管理sdk、avd(Android Virtual Device,Android运行的虚拟设备)以及android项目。
emulator命令
emulator命令在~/sdk/tools目录下。
该命令可用于启动一个avd(使用格式:emulator -avd <avd名称>):
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\tools>emulator -avd AVD
ddms命令
ddms命令在~/sdk/tools目录下。ddms即Dalvik Debug Monitor Service(虚拟机调试监控服务)。
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\tools>ddms
运行该命令后会启动一个图形界面:
ddms命令已过时,可用monitor命令代替。
adb命令
adb(Android Debug Bridge,android调试桥)命令在~/sdk/platform-tools目录下。
adb命令的功能很多,下面简单介绍几个。
1.查看当前运行的模拟器:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\platform-tools>adb devices
List of devices attached
0123456789ABCDEF device
emulator-5554 device
当前启动了两个模拟器。
2.启动模拟器的shell窗口:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\platform-tools>adb shell
$
此时可以在窗口执行一些常用的Linux命令,如ls、rm等等:
$ ls
ls
efs
config
cache
sdcard
acct
mnt
vendor
d
etc
ueventd.rc
ueventd.goldfish.rc
tmp
system
sys
sec_param.ko
sbin
rfs_glue.ko
rfs_fat.ko
res
recovery.rc
proc
lib
j4fs.ko
init.rc
init.goldfish.rc
init.charge.rc
init.bcm21553.rc
init
fsr_stl.ko
fsr.ko
fota.rc
default.prop
data
root
dev
$
3.安装、卸载APK程序:
(1)使用ADB安装APK命令格式如下:
adb install [-r] [-s] <file>
-r表示重新安装该APK包;-s表示将APK包安装到SD卡上,默认安装到内部存储器上;file指定安装的APK包。示例:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\platform-tools>adb install -s E:/bqexpress.apk
3607 KB/s (2943602 bytes in 0.796s)
pkg: /sdcard/tmp/bqexpress.apk
Success
(2)使用ADB卸载APK命令格式如下:
adb uninstall [-k] <package>
-k表示只删除应用程序而保留该应用程序的数据和缓存目录。示例:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\platform-tools>adb uninstall com.XS.UI
Success
mksdcard命令
该命令在~/sdk/tools目录下,用于管理虚拟SD卡。使用格式:
mksdcard [-l label] <size> <file>
示例:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\tools>mksdcard 64M E:\sdcard.img
创建了一个64M的虚拟SD卡,SD卡对应的镜像文件为E:\sdcard.img。
我们使用android create avd命令创建avd的时候指定了SD卡,但是可以在启动avd的时候另外指定SD卡:
E:\soft\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-20131030\sdk\tools>emulator -avd AVD -sdcard E:\sdcard.img