How to create a virtual Android device

Anbox Cloud allows you to stream the whole Android experience next to just individual applications. The following sections will show how to setup such a virtual Android device experience on top of an existing Anbox Cloud deployment.

Create an Application for the Virtual Device

In order to create a virtual device experience we first have to create an application with AMS. This application will not contain any APK and with that will start directly into the Android system launcher and provide the full Android experience.

A very simple application manifest for such an application looks like this:

name: vdev
instance-type: a4.3

Note: If you want to use a GPU for containers created for your new vdev application, use an instance type with GPU support like g4.3.

Extend the Application with Addons

You can also extend the application with addons which install additional applications you want to offer as part of your default experience. You can for example replace the standard Android launcher with a custom one like Lawnchair.

  1. Create the addon directory:

     mkdir -p vdev-support/hooks && cd vdev-support
  2. Download Lawnchair:

     curl -o lawnchair.apk
  3. Create a manifest.yaml file in the vdev-support directory with the following content:

    name: vdev-support
    description: |
      Addon installing and configuring the Lawnchair launcher as the systems default one
  4. Create a post-start script file in the hooks directory with the following content:

    #!/bin/sh -ex
    if  [ "$CONTAINER_TYPE" = "regular" ]; then
      exit 0
    cp "$ADDON_DIR"/lawnchair.apk /var/lib/anbox/data/
    anbox-shell pm install -g -t /data/lawnchair.apk
    # We need to wait until the system has settled after the package installation
    sleep 10
    # Setup lawnchair as our default launcher
    anbox-shell cmd package set-home-activity "$LAUNCHER_ACTIVITY"
    # Once we applied all of our changes we give Android a moment. If we directly
    # return here the Android container will be immediately shutdown.
    sleep 20
  5. Make the script files executable:

     chmod +x hooks/*
  6. Add the addon:

     amc addon add vdev-support .

Once the addon is uploaded to AMS, you can reference it from your application manifest:

name: vdev
instance-type: a4.3
addons: [vdev-support]

The application will now include the Lawnchair and has it configured as the default system launcher.

Launching the new Application

Now that we have the application created in AMS we can go ahead and stream it through the UI of the Anbox Stream Gateway (see Get started with Anbox Cloud (web dashboard) for more details) or your own custom client application built with the Anbox Streaming SDK.