【问题标题】:how to create android emulator in command line with options?如何在命令行中使用选项创建 android 模拟器?
【发布时间】:2012-10-02 12:36:40
【问题描述】:

我想用一些选项在命令行中创建模拟器,比如hw.mainKeys = false。 我需要它是一个 shell 脚本,以便可以在自动化测试中运行,但是 here 我找不到设置这些值的地方。

android create avd 

没有地方指定这些选项。

另一种方法是创建一个“平台”类型的 avd,但是,shell 是一种交互式 shell,对人类来说很好,但对脚本来说很难

Android 4.1 is a basic Android platform.
Do you wish to create a custom hardware profile [no]yes 

Name of the AVD being run: 
avd.name [<build>]:

是否有一些工具我可以将选项作为参数传递,例如 --hw.mainKeys false

【问题讨论】:

    标签: android android-emulator automation


    【解决方案1】:

    您可以创建带有所需参数的文本文件 config.ini

    hw.lcd.density=252
    sdcard.size=32M
    skin.name=NEXUS-ONE
    skin.path=platforms/android-10/skins/NEXUS-ONE
    hw.cpu.arch=arm
    hw.keyboard.lid=no
    abi.type=armeabi
    hw.keyboard=no
    vm.heapSize=24
    hw.ramSize=256
    image.sysdir.1=platforms/android-10/images/
    

    见官方文档here

    【讨论】:

    • 以后如何使用config.ini?
    • 知道了。它可以复制到 name.avd/ 文件夹。谢谢
    • 自 2016 年 8 月起,不再支持“android 工具”,正如文档页面 developer.android.com/studio/tools/help/android.html 上的注释所述。一方面,这解释了为什么我仍然无法在 Travis CI 中正常工作,我在命令行中使用“android create avd”,另一方面,使这个答案过时了 - 看起来我们需要寻找一些从命令行创建模拟器的新方法...
    • @david.schreiber 自从我之前的评论以来,我通过由 Android Studio 创建的 config.ini 文件提供大部分配置参数,设法最大限度地减少了“android 工具”命令行参数的使用。见github.com/andstatus/andstatus/blob/master/.travis.yml
    • 感谢您回来@yvolk!我现在使用类似的方法来预加载不同的 AVD 配置文件(对于我的用例),效果很好?
    【解决方案2】:

    来自android --help create avd

       Usage:
       android [global options] create avd [action options]
       Global options:
      -s --silent     : Silent mode, shows errors only.
      -v --verbose    : Verbose mode, shows errors, warnings and all messages.
         --clear-cache: Clear the SDK Manager repository manifest cache.
      -h --help       : Help on a specific command.
    
                     Action "create avd":
      Creates a new Android Virtual Device.
      Options:
      -t --target  : Target ID of the new AVD. [required]
      -a --snapshot: Place a snapshots file in the AVD, to enable persistence.
      -c --sdcard  : Path to a shared SD card image, or size of a new sdcard for
                 the new AVD.
      -p --path    : Directory where the new AVD will be created.
      -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.
      -n --name    : Name of the new AVD. [required]
      -s --skin    : Skin for the new AVD.
      -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.
      -f --force   : Forces creation (overwrites an existing AVD)
    

    【讨论】:

      【解决方案3】:

      不推荐使用的命令具有较少的命令行选项,但它们是:

      $ $ANDROID_HOME/tools/bin/avdmanager --help create 
      
      Usage:
            avdmanager [global options] create [action options]
            Global options:
        -s --silent     : Silent mode, shows errors only.
        -v --verbose    : Verbose mode, shows errors, warnings and all messages.
           --clear-cache: Clear the SDK Manager repository manifest cache.
        -h --help       : Help on a specific command.
      
      Valid actions are composed of a verb and an optional direct object:
      - create avd          : Creates a new Android Virtual Device.
      
      Action "create avd":
        Creates a new Android Virtual Device.
      Options:
        -a --snapshot: Place a snapshots file in the AVD, to enable persistence.
        -c --sdcard  : Path to a shared SD card image, or size of a new sdcard for
                       the new AVD.
        -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.
        -p --path    : Directory where the new AVD will be created.
        -k --package : Package path of the system image for this AVD (e.g.
                       'system-images;android-19;google_apis;x86'). [required]
        -n --name    : Name of the new AVD. [required]
        -f --force   : Forces creation (overwrites an existing 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.
        -d --device  : The optional device definition to use. Can be a device index
                       or id.
      

      【讨论】:

        【解决方案4】:

        看看here

        android create avd -n Ev o4G -t 9 -c 8000M -s 480-800
        

        【讨论】:

        • 我问的不是名字、目标、皮肤。但其他选项
        【解决方案5】:

        只需使用 echo no | android create avd -n name -t 9

        【讨论】:

        • 关于你的回答,OP应该先运行“android list targets”并选择相关的目标,他可能没有9号目标。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-27
        • 2017-01-16
        • 1970-01-01
        • 2019-07-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多