【问题标题】:How to create Android Virtual Device with command line and avdmanager?如何使用命令行和 avdmanager 创建 Android 虚拟设备?
【发布时间】:2017-03-14 17:39:48
【问题描述】:

我无法使用 avdmanager 命令行创建设备:

$ Android/Sdk/tools/bin/avdmanager create avd --name Nexus6P --tag 11 --package 'system-images;android-23;google_apis;x86_64'
Error: Invalid --tag 11 for the selected package.

$ Android/Sdk/tools/bin/avdmanager create avd --name Nexus6P --package 'system-images;android-23;google_apis;x86_64'
Error: Invalid --tag default for the selected package.

$ Android/Sdk/tools/bin/avdmanager list
Available Android Virtual Devices:
Available devices definitions:
...
---------
id: 11 or "Nexus 6P"
    Name: Nexus 6P
    OEM : Google
---------

有什么想法吗?

【问题讨论】:

    标签: android


    【解决方案1】:

    @Gregriggins36 的解决方案有效。这是我在Linux(Fedora 27)上使用的详细解决方案

    列出可用的设备定义:

    ~/Android/Sdk/tools/bin/avdmanager list
    ...
    ---------
    id: 11 or "Nexus 6P"
        Name: Nexus 6P
        OEM : Google
    ---------
    ...
    

    根据设备定义"Nexus 6P"创建虚拟设备

    ~/Android/Sdk/tools/bin/avdmanager create avd --force --name Nexus6P --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64' --device "Nexus 6P"

    列出可用的虚拟设备

    ~/Android/Sdk/tools/bin/avdmanager list avd
    Name: Nexus6P
    Device: Nexus 6P (Google)
    Path: /home/guillaume/.android/avd/Nexus6P.avd
    Target: Google APIs (Google Inc.)
            Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86_64
    

    开始模拟我们的新虚拟设备

    ~/Android/Sdk/tools/emulator -avd Nexus6P -skin 1440x2560

    遗憾的是,online documentation 落后于实际工具。使用--help 运行会显示您可以使用的所有标志,包括-d

    $  avdmanager create avd --help
    
    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.
      -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').
      -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.
    
    

    【讨论】:

    • 使用最新的构建工具,-skin 1440x2560 不再能够正常工作。不过,我刚刚通过添加-d pixel_xl 创建了一个具有正确硬件配置文件和分辨率 的pixel-xl 模拟器。
    • 我在哪里可以找到名为Nexus 6P 的设备列表?
    【解决方案2】:

    如果你不在乎它是 Nexus 6P,你可以运行

    echo no | Android/Sdk/tools/bin/avdmanager create avd --force --name testAVD --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64'
    

    【讨论】:

    • 感谢您,cli 工作在这里:echo no | Android/Sdk/tools/bin/avdmanager create avd --force --name testAVD --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64' 您可以编辑您的帖子以接受您的答案。
    • @Gregriggins36 如果我在乎?
    • 对不起@cur4所以我还想不出办法
    • 通过将--device "Nexus 6P" 选项传递给avdmanager(参见avdmanager create avd -h)。但是使用当前的 25.3.1 工具,它会创建硬件配置文件,但会忽略分辨率。启动模拟器时传递你的分辨率emulator @avd_name ..more params here.. -skin 1440x2560
    • @franzisk_br 不知道为什么。基于此developer.android.com/studio/command-line/…,它应该在~/.android/avd/ 中创建AVD。您可以随时尝试通过在命令中添加 -p ~/.android/avd 来强制它
    【解决方案3】:

    这是我在 Mac 上运行的命令。
    注意:

    1. x86 和 x86_64 是不同的 ABI。
    2. 需要先从sdkmanager下载system_image

    $  avdmanager create avd --force --name testAVD --abi google_apis/x86 --package 'system-images;android-23;google_apis;x86'
    
    Do you wish to create a custom hardware profile? [no] no
    
    $  avdmanager list avd
    
    
    Name: testAVD
    Path: /Users/xj/.android/avd/testAVD.avd
    Target: Google APIs (Google Inc.)
          Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86
    

    【讨论】:

      【解决方案4】:

      这是我的 Powershell 版本

      • 下载系统映像
      • 设置合适的分辨率
      • 添加 hw.keyboard=yes 以使您的 PC 中的密钥能够发送到模拟器

      https://gist.github.com/shalva97/dd5aa1aad691763a87a5d40f172803e2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多