您的位置:首页 > 移动开发 > Android开发

Android命令行创建并运行 AVD模拟器

2016-06-23 20:50 411 查看



1.查看支持的模拟版本Android版本号

通过cmd进入 Android sdk 目录下的tools目录

不要给我没指定你:Android sdk 目录下的tools目录就直接执行android list或其它语句

当cmd进入tools目录后

执行:

../tools>android list

或者更直接:

cmd> android list targets  //这样就只会显示Available Android targets

显示:

C:\Android\android-sdk\tools>android list
Available Android targets:
----------
id: 1 or "android-10"
     Name: Android 2.3.3
     Type: Platform
     API level: 10
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
 Tag/ABIs : default/armeabi
----------
id: 2 or "android-11"
     Name: Android 3.0
     Type: Platform
     API level: 11
     Revision: 2
     Skins: WXGA (default)
 Tag/ABIs : default/armeabi
----------
id: 3 or "android-15"
     Name: Android 4.0.3
     Type: Platform
     API level: 15
     Revision: 5
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800
 Tag/ABIs : default/armeabi-v7a
----------
id: 4 or "android-18"
     Name: Android 4.3.1
     Type: Platform
     API level: 18
     Revision: 3
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a
----------
id: 5 or "android-19"
     Name: Android 4.4.2
     Type: Platform
     API level: 19
     Revision: 4
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.
----------
id: 6 or "android-21"
     Name: Android 5.0.1
     Type: Platform
     API level: 21
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA8
4000
00, WXGA800-7in, AndroidWearRound, AndroidWearSquare, AndroidWearRo
und, AndroidWearSquare
 Tag/ABIs : android-tv/armeabi-v7a, android-tv/x86, android-wear/armeabi-v7a, an
droid-wear/x86
----------
id: 7 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: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800
 Tag/ABIs : default/armeabi-v7a
----------
id: 8 or "Google Inc.:Google APIs:18"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 3
     Description: Android + Google APIs
     Based on Android 4.3.1 (API level 18)
     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: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : default/armeabi-v7a


2.创建AVD模拟器:

从上述 “Available Android targets” 查找创建AVD所需要的Android sdk 版本号,即界面中id后的那个数字,然后输入下面的命令:

../tools> android create avd -n  Sim2 -t  1

或者

../tools> android create avd --name Sim2  --target 1

运行结果:

Auto-selecting single ABI armeabi-v7a
Created AVD 'Sim2' based on Google APIs (Google Inc.), ARM (armeabi-v7a) process
or,
with the following hardware config:
hw.lcd.density=240
hw.ramSize=512
vm.heapSize=48


创建带SD卡的模拟器

先创建镜像文件(依旧是tools目录下):

cmd>mksdcard  128M sdcard.img

创建avd,附带-c参数

cmd>android create avd -n  Sim2 -t 1 -c "the path to SD"

(完整的例子:android create avd -n testavd  -t 42 -c 70M -p c:\AVD -s 600x700 -b armeabi-v7a)

参数详细:

-t  --target 新的AVD的Target ID(必须);

-c --sdcard 指向一个共享的SD存储卡的路径或者是为新的AVD定制的新的SD存储卡的容量大小.如:-t 50M.("M"必须大写)

-p --path 新AVD将被创建的位置路径.

-n  --name新AVD的名字(必须)

-f   --force 强制创建(覆盖已存在的AVD)

-s  --skin 新AVD的皮肤.

-b --abi :The ABI to use for the AVD.The default is to auto-select the ABI if the platform has only one ABI for its system images.例如:android-17里面的abi有armeabi-v7a,和mips,还有x86,共三个.此时就需要用这个参数指定abi.如 果只有一个abi,则不需要指定这个参数。

 

来源: <http://blog.csdn.net/qy_qingyan/article/details/11797599>

 


3.查看avd是否创建成功

cmd>android  list avd


4.运行启动模拟器

命令行中创建成功后,我们去eclipse中,使用 Android SDK and AVD Manager 查看,就会看到我们刚才创建的sim2模拟器。看不到的话,刷新下。

或者,我们依旧在命令行下启动运行模拟器

cmd> emulator -avd   Sim2



cmd> emulator  @Sim2

注意:运行期间不能关闭命令行,关闭命令行时模拟器也会关闭。


5.删除AVD模拟器

cmd> android delete avd -n  Sim2

其实create avd 还有其他参数可以用,自己可以用执行:

C:\Android\android-sdk>android -h create avd

       Usage:
       android [global options] create avd [action options]
       Global options:
  -h --help       : Help on a specific command.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -s --silent     : Silent mode, shows errors only.

                     Action "create avd":
  Creates a new Android Virtual Device.
Options:
  -g --tag     : The sys-img tag to use for the AVD. The default is to
                 auto-select if the platform has only one tag for its system
                 images.
  -c --sdcard  : Path to a shared SD card image, or size of a new sdcard for
                 the new AVD.
  -n --name    : Name of the new AVD. [required]
  -a --snapshot: Place a snapshots file in the AVD, to enable persistence.
  -p --path    : Directory where the new AVD will be created.
  -f --force   : Forces creation (overwrites an existing AVD)
  -s --skin    : Skin for the new AVD.
  -t --target  : Target ID of the new AVD. [required]
  -b --abi     : The ABI to use for the AVD. The default is to auto-select the
                 ABI if the platform has only one ABI for its system images.
  -d --device  : The optional device definition to use. Can be a device index
                 or id.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: