android命令實戰手冊
android.bat –h 或 android.bat –help
(1)android.bat create avd -t 1 -c 256M -p
E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/images -n avd16 -f -s HVGA
(2)android.bat create avd -t 2 -c 256M -p
E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/images -n avd2 -f -s HVGA
以上,用不同的設定建立avd.
(3)直接用”android.bat”命令可以啟動Android SDK圖開介面(如下圖),用它也可以建立avd;
(4)在eclipse中,點選工具欄中的“open the avd and SDK manager”圖示來開啟上圖。
E:/android_sdk/android-sdk-windows-1.6_r1/tools>android.bat list
Available Android targets:
id: 1
Name: Android 1.5
Type: Platform
API level: 3
Revision: 1
Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
id: 2
Name: Android 1.6
Type: Platform
API level: 4
Revision: 1
Skins: HVGA (default), QVGA, WVGA800, WVGA854
id: 3
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 1.5 (API level 3)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: QVGA-P, HVGA-L, HVGA (default), QVGA-L, HVGA-P
id: 4
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 1.6 (API level 4)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WVGA854, HVGA (default), WVGA800, QVGA
Available Android Virtual Devices:
Name: avd16
Path: C:/Documents and Settings/lizhongyi/.android/avd/avd16.avd
Target: Android 1.6 (API level 4)
Skin: HVGA
---------
Name: avd2
Path: C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd
Target: Android 1.6 (API level 4)
Skin: QVGA
E:/android_sdk/android-sdk-windows-1.6_r1/tools>android list target
Available Android targets:
id: 1
Name: Android 1.5
Type: Platform
API level: 3
Revision: 1
Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
id: 2
Name: Android 1.6
Type: Platform
API level: 4
Revision: 1
Skins: HVGA (default), QVGA, WVGA800, WVGA854
id: 3
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 1.5 (API level 3)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: QVGA-P, HVGA-L, HVGA (default), QVGA-L, HVGA-P
id: 4
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 1.6 (API level 4)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WVGA854, HVGA (default), WVGA800, QVGA
12emulator.exe
(1) 最簡單的方法(用avd):
emulator -avd avd2
(2) 按尺寸啟動模擬器
emulator.exe -avd avd2 -scale 0.7
(3) 啟動userdata.img
emulator -data userdata.img
(4) 啟動system.img
emulator -data system.img
(5) 使用-verbose選項
E:/android_sdk/android-sdk-windows-1.6_r1/tools>emulator-verbose -avd avd2
emulator: found SDK root at E:/android_sdk/android-sdk-windows-1.6_r1
emulator: root virtual device file at C:/Documents and Settings/lizhongyi/.android/avd/avd2.ini
emulator: virtual device content at C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd
emulator: virtual device config file: C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd/config.ini
emulator:locking user data image at C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd/userdata-qemu.img
emulator:locking cache image at C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd/cache.img
emulator: ignoring non-existing SD Card at C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd/sdcard.img: No such file or directory
emulator: found skin 'QVGA' in directory: E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/skins
emulator: autoconfig: -skin QVGA
emulator: autoconfig: -skindir E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/skins
emulator: keyset loaded from: C:/Documents and Settings/lizhongyi/.android/default.keyset
emulator: trying to load skin file 'E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/skins/QVGA/layout'
emulator: skin network speed: 'full'
emulator: skin network delay: 'none'
emulator: registered 'boot-properties' qemud service
emulator: registered 'boot-properties' qemud service
emulator: Adding boot property: 'qemu.sf.lcd_density' = '120'
emulator: argv[00] = "emulator"
emulator: argv[01] = "-kernel"
emulator: argv[02] = "E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/images//kernel-qemu"
emulator: argv[03] = "-initrd"
emulator: argv[04] = "E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/images//ramdisk.img"
emulator: argv[05] = "-nand"
emulator: argv[06] = "system,size=0x4200000,initfile=E:/android_sdk/android-sdk-windows-1.6_r1/platforms/android-1.6/images//system.img"
emulator: argv[07] = "-nand"
emulator: argv[08] = "userdata,size=0x4200000,file=C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd/userdata-qemu.img"
emulator: argv[09] = "-nand"
emulator: argv[10] = "cache,size=0x4200000,file=C:/Documents and Settings/lizhongyi/.android/avd/avd2.avd/cache.img"
emulator: argv[11] = "-serial"
emulator: argv[12] = "android-kmsg"
emulator: argv[13] = "-serial"
emulator: argv[14] = "android-qemud"
emulator: argv[15] = "-append"
emulator: argv[16] = "qemu=1 console=ttyS0 android.checkjni=1 android.qemud=ttyS1 android.ndns=1"
emulator: argv[17] = "-m"
emulator: argv[18] = "96"
emulator: mapping 'system' NAND image to C:/DOCUME~1/LIZHON~1/LOCALS~1/Temp//AndroidEmulator/TMP834.tmp
emulator: using 'winaudio' audio input backend
emulator: using 'winaudio' audio output backend
emulator: control console listening on port 5556, ADB on port 5557
emulator: sent '0012host:emulator:5557' to ADB server
emulator: ping program: E:/android_sdk/android-sdk-windows-1.6_r1/tools/ddms.bat
emulator: ping command: C:/WINDOWS/system32/cmd.exe /C "E:/android_sdk/android-sdk-windows-1.6_r1/tools/ddms.bat" ping emulator 1.11
(6) 使用-logcat 選項
emulator-logcatmain -avd avd2
(7) 使用-trace選項
E:/android_sdk/android-sdk-windows-1.6_r1/tools>emulator-trace main(或events,或radio) -avd avd2
-- When done tracing, exit the emulator. --
emulator: emulator window was out of view and was recentred
或者:
E:/android_sdk/android-sdk-windows-1.6_r1/tools>emulator-trace radio -trace main -trace radio -avd avd2
(7) 使用-kernel和-ramdisk選項
E:/android_sdk/android-sdk-windows-1.6_r1/tools>emulator -kernel ../platforms/android-1.6/images/kernel-qemu -ramdisk ../platforms/android-1
.6/images/ramdisk.img -debug-kernel -verbose -avd avd2
(7) 使用-netfast選項
E:/android_sdk/android-sdk-windows-1.6_r1/tools>emulator-netfast -avd avd2
每一個執行中的模擬器例項都包括一個控制檯,你可以利用控制檯動態的查詢和控制模擬裝置的環境。例如,你可以利用控制檯動態的管理埠對映和網路特性,還可以模擬電話時間。要想進入控制檯輸入命令,你需要使用telnet連線到控制檯的埠號。
可以使用下面的命令隨時隨地連線到任何一個執行中的模擬器例項:
telnet localhost 埠號
假設第一個模擬器例項的控制檯使用5554埠,下一個例項使用的埠號會加2,比如5556、5558……等。你可以在啟動模擬器是使用-verbose選項來檢測該模擬器例項使用的埠號,在除錯輸出的找到以”emulator console running on port number”這一行。另外, 你可以在命令列中使用adb devices來檢視模擬器例項和他們的埠列表。最多可以有16個模擬器例項同時執行控制檯。
(1)進入控制檯
先在一個cmd視窗中啟動一個模擬器, 再開啟一個cmd視窗,執行telnet命令,如下:
E:/android_sdk/android-sdk-windows-1.6_r1/tools> telnet localhost 5556
( 因為在我的PC上,啟動了兩個模擬器, 一個用的是5554埠,另一個用的是5556埠.這裡,控制的是使用5556埠的模擬器)
進入後,如下圖:
(2)gsm測試
輸入
gsm voice on
ok
則可以在模擬器上看到3G圖示,並且網路圖示處於有訊號狀態。
而執行
gsm voice off
ok
後,3G圖示消失,並且網路圖示處於關閉(X)狀態。
gsm call 13522543026
ok
後,模擬器有如下反應:
(3)sms測試
sms send 13522543026 hello
ok
則, 在模擬器的messaging中,就會看到有一條簡訊了.
如圖:
13ddms.bat
E:/android_sdk/android-sdk-windows-1.6_r1/tools>ddms
02:30 I/ddms: Created: [Debugger 8600-->568 inactive]
02:30 I/ddms: Created: [Debugger 8601-->617 inactive]
02:30 I/ddms: Created: [Debugger 8602-->619 inactive]
02:30 I/ddms: Created: [Debugger 8603-->657 inactive]
02:30 I/ddms: Created: [Debugger 8604-->670 inactive]
02:30 I/ddms: Created: [Debugger 8605-->681 inactive]
這和eclipse中的ddms是一樣的.
4adb
1.14.1Adb help:
直接執行adb會顯示出adb的help資訊.如下:
E:/android_sdk/android-sdk-windows-1.6_r1/tools>adb -help
Android Debug Bridge version 1.0.22
-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 <serial number>- directs command to the USB device or emulator with
the given serial number
-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- list all connected 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
(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] <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)
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 help- show this help message
adb version- show version num
DATAOPTS:
(no option)- don't touch the data partition
-w- wipe the data partition
-d- flash the data partition
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 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 root- restarts adb with root permissions
networking:
adb ppp <tty> [parameters]- Run PPP over USB.
Note: you should not automatically start a PPP connec