1. 程式人生 > >android 命令列模式啟動模擬器

android 命令列模式啟動模擬器

一般啟動模擬器需要兩個步驟:
1.建立AVD(Android Virtual Device)
2.啟動emulator


當然也可以直接用emulator直接載入userdata.img映象啟動,這個是為什麼我也不明白,這是我在命令列下面只輸入emulator報錯時,出現的提示資訊

?
emulator: ERROR: You did not provide the name of an Android Virtual Device with the '-avd <name>'option. Read -help-avd for more information. If you *really* want to *NOT* run an AVD, consider using
'-data <file>' to specify a data partition image file (I hope you know what you're doing). <BR>#命令如下<BR>emulator -data ~/xxxx/userdata.img

至於為什麼要用上面說的那種方法,我也不太清楚,下面講一下一般方法:
1.建立AVD
輸入android create avd出現錯誤,並出現提示資訊:

?
Error: The parameters --name, --target must bedefined for
action 'create avd' Usage: android [global options] create avd [action options] Global options: -s --silent Silent mode: only errors are printed out. -h --help Help on a specific command. -v --verbose Verbose mode: errors, warnings and informational messages are printed. Action "create avd": Creates a new Android Virtual Device.
Options: -c --sdcard Path to a shared SD card image, or size of a new sdcardfor the new AVD -s --skin Skinfor the new AVD -a --snapshot Place a snapshots file in the AVD, to enable persistence. -n --name Name of the new AVD [required] -p --path Directory where the new AVD will be created -t --target Target ID of the new AVD [required] -f --force Forces creation (overwrites an existing AVD)

幫助資訊還是很足的,下面這個命令挺重要的,就是檢視target

?
android list target #就是create avd時需要target的引數 Available Android targets: id: 1 or "android-8" Name: Android 2.2 Type: Platform API level: 8 Revision: 2 Skins: WQVGA432, WQVGA400, HVGA, WVGA854, QVGA, WVGA800 (default)

如果需要sdcard的話還要先建立一個sdcard.img

?
mksdcard -l sdcard 512M ~/xx/sdcard.img

這樣就很容易寫出create avd命令了:

?
android create avd -c ~/xxx/sdcard.img -n emulator2011 -p ~/test/ -t 1 -f

不太清楚為什麼每次都要加-f引數,我test目錄下也沒有建立別的avd,不加的話會建立不成功。

2.啟動模擬器

?
android list avd emulator @emulator2011

上述命令就是啟動模擬器。

其實上面兩個步驟就是對應eclipse中建立avd和啟動模擬器的過程,使用eclipse穿件avd,它會在家目錄下建立.android的隱藏資料夾,將avd的資訊全都放到這裡面


android 2.2的原始碼中也有上面說的那些命令,在~/xxxx/out/host/Linux-x86/bin目錄下面