使用 Android emulator 有两种方式,1) Android SDK , 2) 自己 repo sync Android 源代码,编译,运行 emulator.
1). SDK emulator
a). 将 一下路径加入到环境变量:
< android-sdk-linux >/tools
这是为了使用 android 和 emulator 这两个可执行文件,分别用于创建 emulator 和运行。
b). $ android list targets 列出所有可用的targets
android-sdk-linux$ android list targets
Available Android targets:
----------
id: 1 or "android-3"
Name: Android 1.5
Type: Platform
API level: 3
Revision: 4
Skins: HVGA (default), QVGA-L, QVGA-P, HVGA-P, HVGA-L
ABIs : armeabi
----------
id: 2 or "android-4"
Name: Android 1.6
Type: Platform
API level: 4
Revision: 3
Skins: WVGA800 (default), HVGA, WVGA854, QVGA
ABIs : armeabi
----------
id: 3 or "android-7"
Name: Android 2.1
Type: Platform
API level: 7
Revision: 3
Skins: WVGA800 (default), HVGA, WVGA854, WQVGA432, WQVGA400, QVGA
ABIs : armeabi
----------
id: 4 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 3
Skins: WVGA800 (default), HVGA, WVGA854, WQVGA432, WQVGA400, QVGA
ABIs : armeabi
----------
id: 5 or "android-10"
Name: Android 2.3.3
Type: Platform
API level: 10
Revision: 2
Skins: WVGA800 (default), HVGA, WVGA854, WQVGA432, WQVGA400, QVGA
ABIs : armeabi, x86
----------
id: 6 or "android-11"
Name: Android 3.0
Type: Platform
API level: 11
Revision: 2
Skins: WXGA (default)
ABIs : armeabi
----------
id: 7 or "Google Inc.:Google APIs:11"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 3.0 (API level 11)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WXGA (default)
ABIs : armeabi
----------
id: 8 or "android-12"
Name: Android 3.1
Type: Platform
API level: 12
Revision: 3
Skins: WXGA (default)
ABIs : armeabi
----------
id: 9 or "Google Inc.:Google APIs:12"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 3.1 (API level 12)
Libraries:
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WXGA (default)
ABIs : armeabi
----------
id: 10 or "Google Inc.:Google TV Addon:12"
Name: Google TV Addon
Type: Add-On
Vendor: Google Inc.
Revision: 2
Based on Android 3.1 (API level 12)
Skins: WXGA, 1080p-overscan, 1080p, 720p-overscan, 720p (default)
ABIs : x86
----------
id: 11 or "android-13"
Name: Android 3.2
Type: Platform
API level: 13
Revision: 1
Skins: WXGA (default)
ABIs : armeabi
----------
id: 12 or "Google Inc.:Google APIs:13"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 3.2 (API level 13)
Libraries:
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WXGA (default)
ABIs : armeabi
----------
id: 13 or "Google Inc.:Google TV Addon:13"
Name: Google TV Addon
Type: Add-On
Vendor: Google Inc.
Revision: 1
Based on Android 3.2 (API level 13)
Skins: WXGA, 1080p-overscan, 1080p, 720p-overscan, 720p (default)
ABIs : x86
----------
id: 14 or "android-14"
Name: Android 4.0
Type: Platform
API level: 14
Revision: 3
Skins: WVGA800 (default), HVGA, WXGA720, WVGA854, WSVGA, WQVGA432, WQVGA400, WXGA800, QVGA
ABIs : armeabi-v7a
----------
id: 15 or "Google Inc.:Google APIs:14"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 4.0 (API level 14)
Libraries:
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, WSVGA, WXGA720, HVGA, WQVGA432, QVGA, WVGA800 (default), WXGA800
ABIs : armeabi-v7a
----------
id: 16 or "android-15"
Name: Android 4.0.3
Type: Platform
API level: 15
Revision: 3
Skins: WVGA800 (default), HVGA, WXGA720, WVGA854, WSVGA, WQVGA432, WQVGA400, WXGA800, QVGA
ABIs : armeabi-v7a, mips, x86
----------
id: 17 or "Google Inc.:Google APIs:15"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 4.0.3 (API level 15)
Libraries:
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, WSVGA, WXGA720, HVGA, WQVGA432, QVGA, WVGA800 (default), WXGA800
ABIs : armeabi-v7a
----------
id: 18 or "android-16"
Name: Android 4.1.2
Type: Platform
API level: 16
Revision: 4
Skins: WVGA800 (default), HVGA, WXGA720, WVGA854, WSVGA, WXGA800-7in, WQVGA432, WQVGA400, WXGA800, QVGA
ABIs : armeabi-v7a, mips, x86
----------
id: 19 or "Google Inc.:Google APIs:16"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 4.1.2 (API level 16)
Libraries:
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, WSVGA, WXGA800-7in, WXGA720, HVGA, WQVGA432, QVGA, WVGA800 (default), WXGA800
ABIs : armeabi-v7a
----------
id: 20 or "android-17"
Name: Android 4.2.2
Type: Platform
API level: 17
Revision: 2
Skins: WVGA800 (default), HVGA, WXGA720, WVGA854, WSVGA, WXGA800-7in, WQVGA432, WQVGA400, WXGA800, QVGA
ABIs : armeabi-v7a, mips, x86
----------
id: 21 or "Google Inc.:Google APIs:17"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 4.2.2 (API level 17)
Libraries:
* com.google.android.media.effects (effects.jar)
Collection of video effects
* com.android.future.usb.accessory (usb.jar)
API for USB Accessories
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, WSVGA, WXGA800-7in, WXGA720, HVGA, WQVGA432, QVGA, WVGA800 (default), WXGA800
ABIs : armeabi-v7a
这一步主要是获得 target id
c).$ android create avd -n android-arm-emulator -t 21 创建 emulator
android-sdk-linux$ android create avd -n android-arm-emulator -t 21
Auto-selecting single ABI armeabi-v7a
Created AVD 'android-arm-emulator' based on Google APIs (Google Inc.), ARM (armeabi-v7a) processor,
with the following hardware config:
hw.lcd.density=240
vm.heapSize=48
hw.ramSize=512
创建好的emulator 位于~/.android 路径下面。
d). 运行 emulator
android-sdk-linux$ emulator -avd android-arm-emulator
e). $ android delete avd -n android-arm-emulator 删除 emulator
android-sdk-linux$ android delete avd -n android-arm-emulator
Deleting file /home/qiang/.android/avd/android-arm-emulator.ini
Deleting folder /home/qiang/.android/avd/android-arm-emulator.avd
AVD 'android-arm-emulator' deleted.
参考Android 官方Guide:
http://developer.android.com/tools/devices/managing-avds-cmdline.html
http://developer.android.com/tools/devices/emulator.html
2). 使用 source build emulator
a). 编译 emulator generic
$ . build/envsetup.sh && lunch full-eng && make -j 4
如果刚刚编译完,可以直接在编译的那个shell 中直接执行 $ emulator 运行 emulator
当然你不可能每次为了运行个emulator 都编译代码,所以可以按照下面的操作运行
b). $ . build/envsetup.sh && lunch full-eng && emulator
如果想自己指定 system.img/userdata.img/ramdisk.img/kernel-qemu, etc 可以使用下面的命令:
$ . build/envsetup.sh && lunch full-eng && emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilts/qemu-kernel/arm/kernel-qemu-armv7 -memory 512
参考 Android emulator help 信息:
$ emulator -help-build-images |less
$ emulator -help-build-images
The emulator detects that you are working from the Android build system
by looking at the ANDROID_PRODUCT_OUT variable in your environment.
If it is defined, it should point to the product-specific directory that
contains the generated system images.
In this case, the emulator will look by default for the following image
files there:
- system.img : the *initial* system image.
- ramdisk.img : the ramdisk image used to boot the system.
- userdata.img : the *initial* user data image (see below).
- kernel-qemu : the emulator-specific Linux kernel image.
If the kernel image is not found in the out directory, then it is searched
in <build-root>/prebuilts/qemu-kernel/.
Skins will be looked in <build-root>/development/tools/emulator/skins/
You can use the -sysdir, -system, -kernel, -ramdisk, -datadir, -data options
to specify different search directories or specific image files. You can
also use the -cache and -sdcard options to indicate specific cache partition
and SD Card image files.
For more details, see the corresponding -help-<option> section.
Note that the following behaviour is specific to 'build mode':
- the *initial* system image is copied to a temporary file which is
automatically removed when the emulator exits. There is thus no way to
make persistent changes to this image through the emulator, even if
you use the '-image <file>' option.
- unless you use the '-cache <file>' option, the cache partition image
is backed by a temporary file that is initially empty and destroyed on
program exit.
SPECIAL NOTE: If you are using the emulator with the Android SDK, the
information above doesn't apply. See -help-sdk-images for more details.
emulator 默认是 arm 模拟器, 如果自己编译 linux kernel 的话,需要
$ git clone https://android.googlesource.com/kernel/goldfish.git