docker-android

repository·main·Indexed 27 days ago

https://github.com/hqarroum/docker-android

A minimal, customizable Docker image that runs an Android emulator as a service, designed for CI/CD environments and remote control via ADB or scrcpy. Supports hardware acceleration via /dev/kvm, NVIDIA GPU acceleration via CUDA, and customizable API levels, image types, and architectures.

Tokens
1.4K
Snippets
10
Records
13
Agent score
43%

What's inside docker-android

  1. Customize Android API level and image type during build

    main

    You can specify the Android version, image type, and architecture using build arguments when building the Docker image.

    Build Arguments:

    • API_LEVEL: The API level (e.g., 28).
    • IMG_TYPE: The type of image (e.g., google_apis_playstore).
    • ARCHITECTURE: The CPU architecture. Supported values: x86_64, x86.
    docker build \
      --build-arg API_LEVEL=28 \
      --build-arg IMG_TYPE=google_apis_playstore \
      --build-arg ARCHITECTURE=x86 \
      --tag android-emulator .
  2. Run the Android emulator container

    main

    To run the Android emulator, build the image and then execute it using docker run. You must mount the KVM device (/dev/kvm) for hardware acceleration and expose the ADB port (default 5555).

    Requirements:

    • Ensure at least 4GB of memory and 8GB of disk space (for API 33).
    • Access to /dev/kvm on the host.
    docker run -it --rm --device /dev/kvm -p 5555:5555 android-emulator
  3. Configure ADB keys for Google Play Store images

    main

    When using google_apis_playstore images, the ADB key must match between the emulator and the client.

    1. Generate keys: adb keygen adbkey (produces adbkey and adbkey.pub).
    2. Place these files in the ./keys directory before building to override the defaults.
  4. Persist Android emulator data (AVD)

    main

    By default, emulator images are wiped on restart. To save data/storage (AVD) across container restarts, mount a local directory to the /data directory inside the container. The AVD is named android.

    docker run -it --rm --device /dev/kvm -p 5555:5555 -v ~/android_avd:/data android-emulator
  5. Use an external Android SDK to reduce image size

    main

    To reduce build time and image size, you can skip downloading the SDK during the build and instead mount an existing SDK from your host (e.g., from an NFS share) to /opt/android at runtime.

    1. Build with INSTALL_ANDROID_SDK=0.
    2. Run with a volume mount to /opt/android/.
  6. Configure Android Emulator volumes and persistence

    main

    To persist ADB keys and emulator data, use the following volume mappings:

    • ./keys/adbkey:/root/.android/adbkey:ro: Mounts your local ADB private key as read-only.
    • ./keys/adbkey.pub:/root/.android/adbkey.pub:ro: Mounts your local ADB public key as read-only.
    • ./android_avd:/data: Mounts a local directory to /data to persist the Android Virtual Device (AVD) state across container restarts.
    volumes:
      - ./keys/adbkey:/root/.android/adbkey:ro
      - ./keys/adbkey.pub:/root/.android/adbkey.pub:ro
      - ./android_avd:/data
  7. Configure Android Emulator environment variables

    main

    The following environment variables can be used to tune the emulator's performance and behavior:

    • MEMORY: Amount of memory allocated (in MB).
    • CORES: Number of CPU cores allocated.
    • DISABLE_ANIMATION: Set to true to disable animations.
    • DISABLE_HIDDEN_POLICY: Set to true to disable the hidden policy.
    • SKIP_AUTH: Set to true to skip authentication.
    • ANDROID_ADB_SERVER_ADDRESS: (Commented out in default config) Used to point to an external ADB server, e.g., host.docker.internal.
    environment:
      - DISABLE_ANIMATION=false
      - DISABLE_HIDDEN_POLICY=true
      - SKIP_AUTH=false
      - MEMORY=16384
      - CORES=16
  8. Configure Android Emulator build arguments

    main

    When building the emulator images via docker-compose, you can customize the Android environment using the following build arguments:

    • API_LEVEL: The Android API level (e.g., 34).
    • CMD_LINE_VERSION: The specific version of the command-line tools.
    • IMG_TYPE: The type of system image to use (e.g., google_apis or google_apis_playstore).
    android-emulator:
      build:
        context: .
        args:
          - API_LEVEL=34
          - CMD_LINE_VERSION=11076708_latest
          - IMG_TYPE=google_apis