Android中AVD的使用以及错误处理方法

版权所有,禁止匿名转载;禁止商业使用。

AVD的全称为:Android Virtual Device,就是Android运行的虚拟设备,他是Android的模拟器识别。建立的Android要运行,必须创建AVD,每个AVD上可以配置很多的运行项目。创建AVD的方法有两种。一是通过eclipse开发环境,二是通过命令行创建。


1.1版本的emulator在设置好环境变量后,直接在命令行中输入 emulator就可以启动了,但是1.5版本中加了个所谓的AVD(Android Virtual Device),AVD就相当于是一个模拟器的,不过你可以利用AVD创建基于不同版本的模拟器,然后使用emulator-avd avdName命令启动不同的模拟器,下面就介绍如何创建AVD:


1.查看当前支持版本(在列出的版本中我们需要记住id值,这个值在第2步中使用):


android list targets


2.创建AVD(最后的2表示创建1.5版本的avd):


android create avd –n avdName –t 2


3.查看是否创建成功(如果成功会显示刚才我们创建的avd信息):


android list avd


4.启动模拟器:


emulator -avd avdName


5.选择启动的皮肤(横向的模拟器)


emulator -avd avdName -skin HVGA-L


6.按Ctrl+F11,可以直接改变模拟器的横纵摆放。


7. 实际创建avd的过程以及错误处理方法


首先创建一个avd,使用命令行方式创建,例如:


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命令列出当前的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,因为我用的是administrator登陆的,所以拷贝到这个目录下,实际应该拷贝到相应的C: /Documents and Settings/用户名 下,注意用户名要是英文名。


这时候如果用emluator -avd avd15,会得到如下的错误:


emulator: ERROR: no search paths found in this AVD’s configuration.


Weird, the AVD’s config.ini file is malformed. Try re-creating it.


这个错误的原因是C:/Documents and Settings/Administrator/.android/avd目录中的ini文件中包含了中文字符-我的文档,所以要修改这个ini文件 -Avd15.ini,修改path为path=C:/Documents and Settings/Administrator/.android/avd/avd15.avd。


这时候,就可以启动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模拟器了。


运行eclipse中的工程,选择andorid project.会弹出android AVD Error对话框,选择Yes,


d8d79c7f20d5c05ceff47a0c625204a0.jpg


然后出现android virtual device manager:


473a2bde9a2f05f26c864d01625be647.jpg


直接点击finish,然后出现 android device chooser对话框:


8da84401035c016c033d5798201e8c22.jpg


当前运行的emulator会显示出来,选中它,然后OK.


此时,在emulator中可以显示工程的应用程序。


总结一下:


先启动emulator,然后再运行eclipse中的工程。


0 0