Android中AVD的使用以及錯(cuò)誤處理方法
1.1版本的emulator在設(shè)置好環(huán)境變量后,直接在命令行中輸入 emulator就可以啟動(dòng)了,但是1.5版本中加了個(gè)所謂的AVD(Android Virtual Device),AVD就相當(dāng)于是一個(gè)模擬器的,不過你可以利用AVD創(chuàng)建基于不同版本的模擬器,然后使用emulator-avd avdName命令啟動(dòng)不同的模擬器,下面就介紹如何創(chuàng)建AVD:
1.查看當(dāng)前支持版本(在列出的版本中我們需要記住id值,這個(gè)值在第2步中使用):
android list targets
2.創(chuàng)建AVD(最后的2表示創(chuàng)建1.5版本的avd):
android create avd –n avdName –t 2
3.查看是否創(chuàng)建成功(如果成功會(huì)顯示剛才我們創(chuàng)建的avd信息):
android list avd
4.啟動(dòng)模擬器:
emulator -avd avdName
5.選擇啟動(dòng)的皮膚(橫向的模擬器)
emulator -avd avdName -skin HVGA-L
6.按Ctrl+F11,可以直接改變模擬器的橫縱擺放。
7. 實(shí)際創(chuàng)建avd的過程以及錯(cuò)誤處理方法
首先創(chuàng)建一個(gè)avd,使用命令行方式創(chuàng)建,例如:
D:/android/android-sdk-windows-1.5_r3/tools>android create avd -n avd15 -t 2
Android 1.5 is a basic Android platform.
Do you wish to create a custom hardware profile [no]
Created AVD 'avd15' based on Android 1.5
用android list avd命令列出當(dāng)前的avd:
D:/android/android-sdk-windows-1.5_r3/tools>android list avd
Available Android Virtual Devices:
Name: avd15
Path: D:/我的文檔/.android/avd/avd15.avd
Target: Android 1.5 (API level 3)
Skin: HVGA
注意上面的avd的目錄,把上面目錄中的/.android的文件夾拷貝到C:/Documents and Settings/Administrator,因?yàn)槲矣玫氖莂dministrator登陸的,所以拷貝到這個(gè)目錄下,實(shí)際應(yīng)該拷貝到相應(yīng)的C: /Documents and Settings/用戶名 下,注意用戶名要是英文名。
這時(shí)候如果用emluator -avd avd15,會(huì)得到如下的錯(cuò)誤:
emulator: ERROR: no search paths found in this AVD's configuration.
Weird, the AVD's config.ini file is malformed. Try re-creating it.
這個(gè)錯(cuò)誤的原因是C:/Documents and Settings/Administrator/.android/avd目錄中的ini文件中包含了中文字符-我的文檔,所以要修改這個(gè)ini文件 -Avd15.ini,修改path為path=C:/Documents and Settings/Administrator/.android/avd/avd15.avd。
這時(shí)候,就可以啟動(dòng)emulator了:
D:/android/android-sdk-windows-1.5_r3/tools>emulator -avd avd15
emulator: emulator window was out of view and was recentred
可以看到google的android模擬器了。
運(yùn)行eclipse中的工程,選擇andorid project.會(huì)彈出android AVD Error對(duì)話框,選擇Yes,
然后出現(xiàn)android virtual device manager:
直接點(diǎn)擊finish,然后出現(xiàn) android device chooser對(duì)話框:
當(dāng)前運(yùn)行的emulator會(huì)顯示出來,選中它,然后OK.
此時(shí),在emulator中可以顯示工程的應(yīng)用程序。
總結(jié)一下:
先啟動(dòng)emulator,然后再運(yùn)行eclipse中的工程。