启动模拟器需要两个步骤:
1.创建AVD(Android Virtual Device)
2.启动emulator
一般使用Eclipse开发时,开启一个模拟器就是这么一个过程,其实命令行模式下也是这样。刚开始不知道如何命令行启动模拟器的时候就输入了一个emulator,报错了,出现如下提示:
[html] view plaincopy
- 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).
1.创建AVD
根据提示信息说明,需要先有一个AVD,即一个android的虚拟设备,在命令行输入android create avd,当然前提是在linux中配置好了环境变量,否则会出现找不到命令的错误提示的。如果环境变量配置正确会出现了错误提示信息:
[html] view plaincopy
- Error: The parameters --name, --target must be defined 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 sdcard for the new AVD
- -s --skin Skin for 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)
根据上述所提到的参数,并通过查资料得到了-t --target参数如何获得。在命令行下输入android list target,显示如下:
[html] view plaincopy
- android list 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)
其中的id:这一行就是我们需要的target的参数
如果启动的模拟器还需要sdcard的话,还需要首先创建一个sdcard的镜像
[html] view plaincopy
- mksdcard -l sdcard 512M ~/xx/sdcard.img
这样就很容易写出创建AVD的命令了
[html] view plaincopy
- android create avd -c ~/xxx/sdcard.img -n emulator2011 -p ~/test/ -t 1 -f
2.启动模拟器
首先通过android list avd 查看建好的虚拟设备
[html] view plaincopy
- Available Android Virtual Devices:
- Name: android.2.2
- Path: /home/XXX/.android/avd/android.2.2.avd
- Target: Android 2.2 (API level 8)
- Skin: HVGA
- ---------
- Name: emulator2011
- Path: /home/XXX/test
- Target: Android 2.2 (API level 8)
- Skin: WVGA800
- Sdcard: /home/XXX/sdcard.img
然后通过命令
[html] view plaincopy
- emulator @emulator 2011
就启动了第二个类型的模拟器。
其实用命令行启动模拟器和eclipse里启动是相同的。上面两个步骤就是对应eclipse中创建avd和启动模拟器的过程,使用eclipse创建avd,它会在家目录下建立.android的隐藏文件夹,将avd的信息全都放到这里面。
android create avd -c ~/Desktop/android/sdcard.img -n emulator2015 -p ~/Desktop/android/test/ -t 4 -f
emulator @emulator2015
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure Intel HAXM is properly installed and usable.
CPU acceleration status: HAX is not installed on this machine (/dev/HAX is missing).
前提: CPU 支持 VT (Virtualization Technology), 而且仅限于 Intel CPU
首先要打开SDK Manager 下载intel haxm,下载位置:
android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe
下载完毕后运行IntelHaxm.exe安装,完毕后命令行执行 sc query intelhaxm ,如果 STATE RUNNING 表示安装成功。
打开 SDK Manager 下载 intel x86镜像
创建AVD,CPU选择 intel atom x86
出现emulator: ERROR:This AVD's configuration is missing a kernel file!!的原因是在你的sdk下缺少相应的kernel-qemu文件。 可按如下步骤查找原因: 执行android list avd ,查看你创建的AVD 其中ABI:后面的关键字记住,然后进入你的SDK中..\..\sdk\system-images\android-17,我创建的AVD是API level 17,所以查看的文件是android-17,看这个文件夹中是否有X86的文件 我之前就是因为缺少X86的文件,所以一直报错。 解决方法: 进入Android SDK Manager,查看相应AVD的Packages 缺少X86文件夹就下载Intel x86 Atom System Image 缺少armeabi-v7a文件夹就下载ARM EABI v7a System Image 下载完成就OK 了! 然后再使用命令emulator @(avd名字) - verbose查看 其中有一行显示如下, 报错就是因为它找不到x86下面的kernel-qemu文件!!!