Search code examples
androidcommand-lineandroid-virtual-device

How can I create an AVD from the command line based on the device definitions in the AVD Manager?


In the AVD Manager gui I see a list of Device Definitions, these make it easy to provision a device with given settings.

When I use android list targets I get a different set of results from the device definitions.

Is the list of device definitions accessible through the command line? If so, how can I build a device based on one through the command line?

Update:

When you create a device through the avd gui it creates a config file located at /.android/name-of-your-phone/Config.ini You can add the setup options you want to a new device with -prop example: -prop hw.sdCard=yes -prop sdcard.size=200M, I ran the full command with the -verbose flag and you can see the config it spins up with. It's annoying that the options aren't comma-delineated but whatever.

The full command that wound up working for me was:

$ANDROID_HOME/tools/emulator -avd phone -gpu on -memory 3072 -prop hw.sdCard=yes -prop sdcard.size=200M -prop disk.dataPartition.size=200M

Solution

  • The ones you're seeing (presumably in Android Studio) are pre-packaged with the IDE. If you look in to Android Studio's application files (in Mac) by right clicking on the app file and selecting "Show Package Contents":

    Applications ▸ Android Studio.app ▸ Contents ▸ plugins ▸ android ▸ lib ▸ device-art-resources ▸ device-art.xml

    You'll see something like this:

    ...
    <device id="galaxy_nexus" name="Galaxy Nexus">
        <orientation name="port" size="1101,1709" screenPos="192,213" screenSize="720,1280" shadow="port_shadow.png" back="port_back.png" lights="port_fore.png"/>
        <orientation name="land" size="1847,886" screenPos="304,68" screenSize="1280,720" shadow="land_shadow.png" back="land_back.png" lights="land_fore.png"/>
    </device>
    <device id="nexus_s" name="Nexus S">
        <orientation name="port" size="719,1139" screenPos="119,160" screenSize="480,800" shadow="port_shadow.png" back="port_back.png" lights="port_fore.png"/>
        <orientation name="land" size="1210,586" screenPos="208,44" screenSize="800,480" shadow="land_shadow.png" back="land_back.png" lights="land_fore.png"/>
    </device>
    ...
    

    Furthermore, I've found ConfigGenerator.java class in the SDK folder which has all of these pre-packaged device configuration and definitions in Java. Take a look, I think this is what you may be looking for.

    android-sdks ▸ sources ▸ android-21 ▸ com ▸ android ▸ layoutlib ▸ bridge ▸ intensive ▸ setup ▸ ConfigGenerator.java

    So that being said, you may not have a direct access to use this proprietary avd definitions. But perhaps, you could create a script and use this file as a baseline to build on top and derive at your own solution.

    Hope this helps.