Docker-Android

repository·master·Indexed 12 days ago

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

Containerized Android emulators for application development, testing (Appium, Espresso), and CI/CD integration. Supports Android versions 9.0 through 14.0, Genymotion, VNC access, and hardware acceleration via KVM. Includes a CLI for managing device lifecycles and sub-services like Appium, Xvfb, and noVNC.

Tokens
10.5K
Snippets
28
Records
55
Agent score
93%

What's inside Docker-Android

  1. Compare Normal vs Pro versions of Docker-Android

    master

    The Pro version includes several advanced features not available in the Normal version:

    FeatureNormalPro
    ProxyNoYes (Set up company proxy on fly)
    LanguageNoYes (Set up language on fly)
    Root PrivilegedNoYes (Run commands with security privileges)
    Headless ModeNoYes (Save resources; note: no Web-UI)
    Selenium 4.x IntegrationNoYes (Run Appium UI-Tests against a single Selenium Hub endpoint)
    Multiple Android SimulatorsNoYes (Coming soon)
    Google Play StoreNoYes (Coming soon)
    Video RecordingNoYes (Coming soon)
    User Behavior AnalyticsYesNo
  2. Compare Docker-Android Normal vs Pro versions

    master

    The Pro version is available to active sponsors and includes advanced features for enterprise and testing workflows.

    Key Pro Features:

    • Proxy Support: Set up company proxies on the fly.
    • Language Support: Change emulator language on the fly.
    • Newer Android Versions: Support for Android 15, 16, etc.
    • Root Privileges: Run commands with security privileges.
    • Headless Mode: Save resources by running without a GUI.
    • Selenium 4.x Integration: Run Appium UI-Tests against a single Selenium Hub endpoint.
    • Multiple Simulators: Run multiple Android simulators within a single container.
    • Google Play Store & Video Recording: (Coming soon).
  3. Connect to the emulator via VNC client

    master

    The VNC server inside the container runs on port 5900. You can connect to the emulator using a standard VNC client by mapping the port and optionally setting a password.

    To protect the connection, use the VNC_PASSWORD environment variable.

    docker run -d -p 5900:5900 -e EMULATOR_DEVICE="Samsung Galaxy S10" --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0
  4. Build an Android project and execute unit tests

    master

    You can use docker-android to build Android projects and run their unit tests within a containerized environment. To do this, you must mount your project source code into the container and use the --entrypoint flag to execute your build commands (e.g., ./gradlew build).

    Steps to build a sample project:

    1. Clone a sample Android project (e.g., android/testing-samples).
    2. Run the docker-android container, mounting the specific project directory to /home/androidusr/tmp inside the container.
    3. Set the working directory (-w) to the mounted path.
    4. Override the entrypoint to /bin/bash to execute your build command via the -c flag.
    # 1. Clone the sample project
    git clone git@github.com:android/testing-samples.git
    
    # 2. Build the project using docker-android
    docker run -it --rm \
      -v $PWD/testing-samples/ui/espresso/BasicSample:/home/androidusr/tmp \
      -w /home/androidusr/tmp \
      --entrypoint "/bin/bash" \
      budtmo/docker-android:emulator_11.0_v2.0 -c "./gradlew build"
  5. Quick Start: Run a Docker-Android container

    master

    To run a Docker-Android container, ensure your host machine supports virtualization and has Docker installed. If you are on macOS or Windows, you must use a Virtual Machine running Ubuntu, as the image is designed for Ubuntu environments.

    1. Verify Virtualization: Run kvm-ok to ensure KVM is enabled.
    2. Run Container: Use docker run with the --device /dev/kvm flag to enable hardware acceleration.
    3. Access UI: Open http://localhost:6080 in your browser to interact with the emulator via VNC.

    Available device profiles include Samsung Galaxy S10, Nexus 4, Pixel C, and more.

    # 1. Check virtualization
    sudo apt install cpu-checker
    kvm-ok
    
    # 2. Run the container
    docker run -d -p 6080:6080 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0
    
    # 3. Check emulator status
    docker exec -it android-container cat device_status
  6. Use the Jenkins VNC Viewer plugin for live preview

    master

    To optimize your Jenkins workflow with docker-android, you can use the budtmo/jenkins-plugin-vncviewer-docker-container plugin. This plugin enables a live preview of the Android emulator running within your Docker containers directly from the Jenkins interface.

    https://github.com/budtmo/vncviewer-docker-container-plugin
  7. Control the emulator from the host machine

    master

    You can control the Android emulator running inside a docker-android container from your host machine by exposing the ADB ports and using the host's adb client to connect to the container's IP address.

    Steps to connect:

    1. Expose ADB ports: When running the docker run command, you must map ports 5554 and 5555 from the container to your host machine.
    2. Connect via ADB: Use the adb connect command pointing to the IP address of the Docker machine and port 5555.
    # 1. Run the container with ports exposed
    docker run ... -p 5554:5554 -p 5555:5555 ...
    
    # 2. Connect from your host machine
    # Replace <docker-machine-ip-address> with your actual Docker IP
    adb connect <docker-machine-ip-address>:5555
  8. Access the emulator via Web VNC

    master

    You can access the emulator's display through a web browser by enabling WEB_VNC. The service runs on port 6080 by default.

    Web VNC Endpoints

    If WEB_VNC is activated, you can use the following URL parameters:

    • Autoconnect: http://localhost:6080/?autoconnect=true (accesses the UI directly)
    • View Only: http://localhost:6080/?autoconnect=true&view_only=true (provides read-only access)
    • Password Protected: http://localhost:6080/?autoconnect=true&password=thisissecret (accesses the UI with a specific password)
  9. Override Emulator configuration via file

    master

    To use a custom .ini configuration file for the emulator, you must perform two steps:

    1. Set the EMULATOR_CONFIG_PATH environment variable to the path where the file will exist inside the container.
    2. Mount the local configuration file as a Docker volume (-v) to that exact path.

    Example:

    docker run -d -p 6080:6080 -e EMULATOR_CONFIG_PATH=/tmp/emulator-override-config.ini -v /path/on/your/machine/emulator-override-config.ini:/tmp/emulator-override-config.ini -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_14.0