docker-android Documentation

Android in docker solution with noVNC supported and video recording

15,583 stars Python Python 1 file ยท ~10,070 tokens #alibabacloud#android#android-emulator#aws#azure#cloud#docker#docker-android
RAW Doc

Docker & Self-Hosted Deployment Verified OCI

Deploy docker-android on any server, homelab, or cloud container platform.

1-Click Terminal Command
bash (docker run)
docker run -d --name docker-android -p 5554:5554 --restart always hqarroum/docker-android:latest
Configured Services & Ports
โš™๏ธ android-emulator
image: build locally
๐Ÿ”Œ Ports: 5554:5554, 127.0.0.1:5555:5555
โš™๏ธ android-emulator-cuda
image: build locally
๐Ÿ”Œ Ports: 5554:5554, 127.0.0.1:5555:5555
โš™๏ธ android-emulator-cuda-store
image: build locally
๐Ÿ”Œ Ports: 5554:5554, 127.0.0.1:5555:5555
docker-compose.yml
yaml (docker-compose.yml)
version: "4"
services:
  android-emulator:
    build:
      context: .
      args:
        - API_LEVEL=34
        - CMD_LINE_VERSION=11076708_latest
        - IMG_TYPE=google_apis
    ports:
      - 5554:5554
      - 127.0.0.1:5555:5555
    environment:
      - DISABLE_ANIMATION=false
      - DISABLE_HIDDEN_POLICY=true
      - SKIP_AUTH=false
      #- ANDROID_ADB_SERVER_ADDRESS=host.docker.internal
      - MEMORY=16384
      - CORES=16
    privileged: true
    tty: true
    stdin_open: true
    volumes:
      - ./keys/adbkey:/root/.android/adbkey:ro
      - ./keys/adbkey.pub:/root/.android/adbkey.pub:ro
      - ./android_avd:/data
    extra_hosts:
      - "host.docker.internal:host-gateway"
    devices:
      - /dev/kvm:/dev/kvm

  android-emulator-cuda:
    build:
      context: .
      dockerfile: ./Dockerfile.gpu
      args:
        - API_LEVEL=34
        - CMD_LINE_VERSION=11076708_latest
        - IMG_TYPE=google_apis
    ports:
      - 5554:5554
      - 127.0.0.1:5555:5555
    environment:
      - DISABLE_ANIMATION=false
      - DISABLE_HIDDEN_POLICY=true
      - SKIP_AUTH=false
      #- ANDROID_ADB_SERVER_ADDRESS=host.docker.internal
      - MEMORY=16384
      - CORES=16
    privileged: true
    tty: true
    stdin_open: true
    volumes:
      - ./keys/adbkey:/root/.android/adbkey:ro
      - ./keys/adbkey.pub:/root/.android/adbkey.pub:ro
    extra_hosts:
      - "host.docker.internal:host-gateway"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

  android-emulator-cuda-store:
    build:
      context: .
      dockerfile: ./Dockerfile.gpu
      args:
        - API_LEVEL=34
        - CMD_LINE_VERSION=11076708_latest
        - IMG_TYPE=google_apis_playstore
    ports:
      - 5554:5554
      - 127.0.0.1:5555:5555
    environment:
      - DISABLE_ANIMATION=false
      - DISABLE_HIDDEN_POLICY=true
      - SKIP_AUTH=false
      #- ANDROID_ADB_SERVER_ADDRESS=host.docker.internal
      - MEMORY=16384
      - CORES=16
    privileged: true
    tty: true
    stdin_open: true
    volumes:
      - ./keys/adbkey:/root/.android/adbkey:ro
      - ./keys/adbkey.pub:/root/.android/adbkey.pub:ro
    # volumes:
    #   - ./:/mnt
    extra_hosts:
      - "host.docker.internal:host-gateway"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

README (README.md)

Docker-Android is a docker image built to be used for everything related to Android. It can be used for Application development and testing (native, web and hybrid-app).

Advantages of using this project

  1. Emulator with different device profile and skins, such as Samsung Galaxy S6, LG Nexus 4, HTC Nexus One and more.
  2. Support vnc to be able to see what happen inside docker container
  3. Support log sharing feature where all logs can be accessed from web-UI
  4. Ability to control emulator from outside container by using adb connect
  5. Integrated with other cloud solutions, e.g. Genymotion Cloud
  6. It can be used to build Android project
  7. It can be used to run unit and UI-Test with different test-frameworks, e.g. Appium, Espresso, etc.

List of Docker-Images

Android API Image with latest release version Image with specific release version
9.0 28 budtmo/docker-android:emulator_9.0 budtmo/docker-android:emulator_9.0_
10.0 29 budtmo/docker-android:emulator_10.0 budtmo/docker-android:emulator_10.0_
11.0 30 budtmo/docker-android:emulator_11.0 budtmo/docker-android:emulator_11.0_
12.0 32 budtmo/docker-android:emulator_12.0 budtmo/docker-android:emulator_12.0_
13.0 33 budtmo/docker-android:emulator_13.0 budtmo/docker-android:emulator_13.0_
14.0 34 budtmo/docker-android:emulator_14.0 budtmo/docker-android:emulator_14.0_
- - budtmo/docker-android:genymotion budtmo/docker-android:genymotion_

List of Devices

Type Device Name
Phone Samsung Galaxy S10
Phone Samsung Galaxy S9
Phone Samsung Galaxy S8
Phone Samsung Galaxy S7 Edge
Phone Samsung Galaxy S7
Phone Samsung Galaxy S6
Phone Nexus 4
Phone Nexus 5
Phone Nexus One
Phone Nexus S
Tablet Nexus 7
Tablet Pixel C

Requirements

  1. Docker is installed on your system.

Quick Start

  1. If you use Ubuntu OS on your host machine, you can skip this step. For OSX and Windows OS user, you need to use Virtual Machine that support Virtualization with Ubuntu OS because the image can be run under Ubuntu OS only.

  2. Your machine should support virtualization. To check if the virtualization is enabled is:

    text
    sudo apt install cpu-checker
    kvm-ok
  3. Run Docker-Android container

    text
    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
  4. Open http://localhost:6080 to see inside running container.

  5. To check the status of the emulator

    text
    docker exec -it android-container cat device_status

Persisting data

The default behaviour is to destroy the emulated device on container restart. To persist data, you need to mount a volume at /home/androidusr:
docker run -v data:/home/androidusr budtmo/docker-android:emulator_11.0

WSL2 Hardware acceleration (Windows 11 only)

Credit goes to Guillaume - The Parallel Interface blog

Microsoft - Advanced settings configuration in WSL

  1. Add yourself to the kvm usergroup.

    text
    sudo usermod -a -G kvm ${USER}
  2. Add necessary flags to /etc/wsl.conf to their respective sections.

    text
    [boot]
    command = /bin/bash -c 'chown -v root:kvm /dev/kvm && chmod 660 /dev/kvm'

    Then, using PowerShell, open a notepad on notepad $env:USERPROFILE\.wslconfig. Inside, put these other flags:

    text
    [wsl2]
    nestedVirtualization=true
  3. Restart WSL2 via CMD prompt or Powershell

    text
    wsl --shutdown

command = /bin/bash -c 'chown -v root:kvm /dev/kvm && chmod 660 /dev/kvm' sets /dev/kvm to kvm usergroup rather than the default root usergroup on WSL2 startup.

nestedVirtualization flag is only available to Windows 11.

If this setup does not work, you may have an old WSL version. In that case, ignore \.wslconfig and put everything on /etc/wsl.conf, including the [wsl2] flag.

Use-Cases

  1. Build Android project
  2. UI-Test with Appium
  3. Control Android emulator on host machine
  4. SMS Simulation
  5. Jenkins
  6. Deploying on cloud (Azure, AWS, GCP)

Custom-Configurations

This document contains information about configurations that can be used to enable some features, e.g. log-sharing, etc.

Genymotion

For you who do not have ressources to maintain the simulator or to buy machines or need different device profiles, you can give a try by using Genymotion SAAS. Docker-Android is integrated with Genymotion on different cloud services, e.g. Genymotion SAAS, AWS, GCP, Alibaba Cloud. Please follow this document for more detail.

Emulator Skins

The Emulator skins are taken from Android Studio IDE and Samsung Developer Website

USERS

PRO VERSION

Due to high requests for help and to be able to actively maintain the projects, the creator has decided to create docker-android-pro. Docker-Android-Pro is a sponsor based project which mean that the docker image of pro-version can be pulled only by active sponsor.

The differences between normal version and pro version are:

Feature Normal Pro Comment
user-behavior-analytics Yes No -
proxy No Yes Set up company proxy on Android emulator on fly
language No Yes Set up language on Android emulator on fly
Newer Android version No Yes Support other newer Android version e.g. Android 15, Android 16, etc
root-privileged No Yes Able to run command with security privileged
headless-mode No Yes Save resources by using headless mode
Selenium 4.x integration No Yes Running Appium UI-Tests againt one (Selenium Hub) endpoint for Android- and iOS emulator(s) / device(s)
multiple Android-Simulators No Yes (soon) Save resources by having multiple Android-Simulators on one docker-container
Google Play Store No Yes (soon) -
Video Recording No Yes (soon) Helpful for debugging

This document contains detail information about how to use docker-android-pro.

LICENSE

See License


LICENSE (LICENSE.md)

License Information

Copyright 2023 budi utomo

This program is subject to the terms of the Apache License, Version 2.0 AND the following amendments on forks and data processing. Thus, this is a Custom Apache 2.0 License, NOT a dual-license model you may choose from.

You can obtain a copy of the license at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Forks

Additionally to Apache-2.0, when you fork this repo you are required to either remove our Google Form ID: 1FAIpQLSdrKWQdMh6Nt8v8NQdYvTIntohebAgqWCpXT3T9NofAoxcpkw or stop usage gathering completely.

Data processing agreement

By using this software you agree that the following non-PII (non personally identifiable information) data will be collected, processed and used by the maintainers for the purpose of improving the docker-android project.

By using this software you also grant us a nonexclusive, irrevocable, world-wide, perpetual royalty-free permission to use, modify and publish these data for all purposes, internally or publicly, including the right to sub-license said permission rights.

We collect, process and use the following data:

  • Date and time when Docker-Android started
  • User (it will collect the information about Release Version of Machine), e.g. Linux-5.4.0-146-generic-x86_64-with-glibc2.29_#163-Ubuntu_SMP_Fri_Mar_17_18:26:02_UTC_2023. This does not allow us to track individual users but does enable us to accurately measure user counts
  • City (the information come from https://ipinfo.io)
  • Region (the information come from https://ipinfo.io)
  • Country (the information come from https://ipinfo.io)
  • Release version of Docker-Android
  • Appium (Whether user use Appium or not - The possible value will be "true" or "false")
  • Appium Additional Arguments
  • Web-Log (Whether user use Web-Log feature or not - The possible value will be "true" or "false")
  • Web-Vnc (Whether user use Web-Vnc feature or not - The possible value will be "true" or "false")
  • Screen-Resolution
  • Device Type (Which docker image is used - The possible value will be "emulator" or "geny_cloud" or "geny_aws")
  • Emulator Device (Which device profile and skin is used if the user use device_type "emulator")
  • Emulator Android Version (Which Android version is used if the user use device_type "emulator"
  • Emulator No-Skin feature (Whether user use no-skin feature or not - The possible value will be "true" or "false")
  • Emulator Data Partition
  • Emulator Additional Arguments

End of License Information

More information about anonymized data collection can be seen here


Renovate.Json (renovate.json)

{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}


Cli/Requirements (cli/requirements.txt)

autopep8==2.3.2
click==8.4.2
coverage==7.15.4
mock==5.2.0
pytest==9.1.1
pytest-cov==7.1.0
pytest-xdist==3.8.0
requests==2.34.2
setuptools==84.0.0


Documentations/CUSTOM CONFIGURATIONS (documentations/CUSTOM_CONFIGURATIONS.md)

VNC-CLIENT

Vnc-server inside container is run on port 5900

  1. Run docker-android:

    text
    docker run -d -p 5900:5900 -e EMULATOR_DEVICE="Samsung Galaxy S10" --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0
  2. Connect docker-container using vnc-client

Environment variables that can be passed to docker container for vnc configuration:

Environment Variable Description Example
VNC_PASSWORD protect vnc connection with password docker run ... -e VNC_PASSWORD=thisissecret ...

VNC-WEB

Vnc-web inside container is run on port 6080

Environment variables that can be passed to docker container for vnc configuration:

Environment Variable Description Example
WEB_VNC access inside of the container through web-ui docker run ... -p 6080:6080 -e WEB_VNC=true ...
WEB_VNC_PORT access inside of the container through web-ui on given port (default port 6080) docker run ... -p 6081:6081 -e WEB_VNC=true -e WEB_VNC_PORT=6081 ...

Possible endpoints if WEB_VNC is activated:

Endpoint Description Example
autoconnect access web-ui of vnc direclty http://localhost:6080/?autoconnect=true
view_only give only view access http://localhost:6080/?autoconnect=true&view_only=true
password access web-ui of vnc directly with protected password http://localhost:6080/?autoconnect=true&password=thisissecret

LOG-SHARING

The user has possibility to access log-files through web-ui:

Environment Variable Description Example
WEB_LOG access log-files through web-ui docker run ... -e WEB_LOG=true ...
WEB_LOG_PORT access log-files through web-ui on given port (default port 9000) docker run ... -e WEB_LOG=true -e WEB_LOG_PORT=9001 ...

EMULATOR

Possible environment variable to configure the Emulator:

Environment Variable Description Example
EMULATOR_NAME give emulator name (default name is a combination between Device name and Android version) docker run ... -e EMULATOR_NAME=my_emu ...
EMULATOR_DATA_PARTITION set data partition on emulator (default value 550m) docker run ... -e EMULATOR_DATA_PARTITION=900m ...
EMULATOR_NO_SKIN deploying emulator without skin docker run ... -e EMULATOR_NO_SKIN=true ...

The user can also pass needed arguments to android emulator through environment variable EMULATOR_ADDITIONAL_ARGS. Please check this page for possible arguments that can be passed.

EMULATOR - OVERRIDE CONFIG FILE

To utilize this feature, ensure the following setup:

  • Set the config file path into environment variable EMULATOR_CONFIG_PATH, eg. /tmp/emulator-override-config.ini (the file name doesn't matter)
  • Mount the file as Docker volume (parameter -v for Docker run command) to the path as you set into ENV

Example:

shell
docker run -d -p 6080:6080 -e /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

<- BACK TO README


Documentations/DOCKER ANDROID PRO (documentations/DOCKER-ANDROID-PRO.md)

Docker-Android-Pro

Docker-Android-Pro is a sponsor based project which mean that the docker image of pro-version can be pulled only by active sponsor. After donation, please send email here with following format on subject email: <github_id>-<date-when-donation-is-made>- e.g. [email protected]. The script will validate everything and it will send the access token to that email within 48 hours to be able to pull the pro version of docker-android image. Contact @budtmo if you dont get access token after donation. The access token will be removed as soon as the user become inactive sponsor.

The differences between normal version and pro version are:

Feature Normal Pro Comment
user-behavior-analytics Yes No -
proxy No Yes Set up company proxy on Android emulator on fly
language No Yes Set up language on Android emulator on fly
root-privileged No Yes Able to run command with security privileged
headless-mode No Yes Save resources by using headless mode
Selenium 4.x integration No Yes Running Appium UI-Tests againt one (Selenium Hub) endpoint for Android- and iOS emulator(s) / device(s)
multiple Android-Simulators No Yes (soon) Save resources by having multiple Android-Simulators on one docker-container
Google Play Store No Yes (soon) -
Video Recording No Yes (soon) Helpful for debugging

List of Docker-Images

Android API Type Image with latest release version Image with specific release version
9.0 28 Normal budtmo2/docker-android-pro:emulator_9.0 budtmo2/docker-android-pro:emulator_9.0_
10.0 29 Normal budtmo2/docker-android-pro:emulator_10.0 budtmo2/docker-android-pro:emulator_10.0_
11.0 30 Normal budtmo2/docker-android-pro:emulator_11.0 budtmo2/docker-android-pro:emulator_11.0_
12.0 32 Normal budtmo2/docker-android-pro:emulator_12.0 budtmo2/docker-android-pro:emulator_12.0_
13.0 33 Normal budtmo2/docker-android-pro:emulator_13.0 budtmo2/docker-android-pro:emulator_13.0_
14.0 34 Normal budtmo2/docker-android-pro:emulator_14.0 budtmo2/docker-android-pro:emulator_14.0_
15.0 35 Normal budtmo2/docker-android-pro:emulator_15.0 budtmo2/docker-android-pro:emulator_15.0_
16.0 36 Normal budtmo2/docker-android-pro:emulator_16.0 budtmo2/docker-android-pro:emulator_16.0_
9.0 28 Headless budtmo2/docker-android-pro:emulator_headless_9.0 budtmo2/docker-android-pro:emulator_headless_9.0_
10.0 29 Headless budtmo2/docker-android-pro:emulator_headless_10.0 budtmo2/docker-android-pro:emulator_headless_10.0_
11.0 30 Headless budtmo2/docker-android-pro:emulator_headless_11.0 budtmo2/docker-android-pro:emulator_headless_11.0_
12.0 32 Headless budtmo2/docker-android-pro:emulator_headless_12.0 budtmo2/docker-android-pro:emulator_headless_12.0_
13.0 33 Headless budtmo2/docker-android-pro:emulator_headless_13.0 budtmo2/docker-android-pro:emulator_headless_13.0_
14.0 34 Headless budtmo2/docker-android-pro:emulator_headless_14.0 budtmo2/docker-android-pro:emulator_headless_14.0_
15.0 35 Headless budtmo2/docker-android-pro:emulator_headless_15.0 budtmo2/docker-android-pro:emulator_headless_15.0_
16.0 36 Headless budtmo2/docker-android-pro:emulator_headless_16.0 budtmo2/docker-android-pro:emulator_headless_16.0_
- - Selenium budtmo2/docker-android-pro:selenium budtmo2/docker-android-pro:selenium_

Note: Headless mode does not have any Web-UI

You can always pull the latest image tag. In case you want to see the release version that has been built with a changelog note and use that specific release version, the information will be sent to you as well.

List of Devices

Type Device Name
Phone Samsung Galaxy S10
Phone Samsung Galaxy S9
Phone Samsung Galaxy S8
Phone Samsung Galaxy S7 Edge
Phone Samsung Galaxy S7
Phone Samsung Galaxy S6
Phone Nexus 4
Phone Nexus 5
Phone Nexus One
Phone Nexus S
Tablet Nexus 7
Tablet Pixel C

Proxy

You can enable proxy inside container and Android emulator by passing following environment variables:

  • HTTP_PROXY="http://<docker_bridge_ip>:"
  • HTTPS_PROXY="http://<docker_bridge_ip>:"
  • NO_PROXY="localhost"
  • EMULATOR_PROXY_URL="http://<docker_bridge_ip>:"
  • EMULATOR_PROXY_USER=""
  • EMULATOR_PROXY_PASS=""

Language

You can change the language setting of Android Emulator on the fly by passing following environment variable:

  • EMULATOR_LANGUAGE="<language>"
  • EMULATOR_COUNTRY="<country>"

Selenium

Pull and run image that contains Selenium with Appium urls and its capabilities which is stored inside node.json file:

text
docker run -t --rm --name selenium -p 4444:4444 -v $PWD/pro-example/node.json:/home/seleniumusr/selenium_node_config/node.json budtmo2/docker-android-pro:selenium

<- BACK TO README


Documentations/THIRD PARTY GENYMOTION (documentations/THIRD_PARTY_GENYMOTION.md)

text
export USER="xxx"
	export PASS="xxx"

	docker run -d -p 4723:4723 -v ${PWD}/example/genycloud/saas.json:/home/androidusr/genymotion_template/saas.json -e DEVICE_TYPE=geny_saas -e GENY_SAAS_USER=${USER} -e GENY_SAAS_PASS=${PASS} -e APPIUM=true --name android-container budtmo/docker-android:genymotion
	```
Genymotion Cloud
----------------



You can use Genymotion Android virtual devices in the cloud. They are available on [SaaS](http://bit.ly/2YP0P1l) or as virtual images on AWS, GCP or Alibaba Cloud.

1. On SaaS 
	Use [saas.json](../example/genymotion/saas.json) to define the devices that you want to use. You can specify the port on which the device will start so you don't need to change the device name in your tests every time you need to run those tests. Then run following command

	```
	export AUTH_TOKEN="xxx"

	docker run -d -p 4723:4723 -v ${PWD}/example/genycloud/saas.json:/home/androidusr/genymotion_template/saas.json -e DEVICE_TYPE=geny_saas -e GENY_AUTH_TOKEN=${AUTH_TOKEN} -e APPIUM=true --name android-container budtmo/docker-android:genymotion
	```

    Genymotion has deprecated credential based login since gmsaas 1.10.0, but if necessary, you can still provide them using `-e GENY_SAAS_USER=${USER} -e GENY_SAAS_PASS=${PASS}` instead of `-e GENY_AUTH_TOKEN=${AUTH_TOKEN}`.

	The deployed device(s) are automatically connected with adb inside docker container. Stopping the emulator will remove all deployed device(s) on Genymotion SaaS and user will be logged out at the end.

	```
	docker stop android-container
	```


	In case you are interesed to play around with Genymotion on SaaS, you can register to [this link](http://bit.ly/2YP0P1l) to get free minutes for free.

2. On AWS 
	Use [aws.json](../example/genymotion/aws.json) to define the devices that you want to use. You can specify the port on which the device will start so you don't need to change the device name in your tests every time you need to run those tests. Then run following command

	```
	export AWS_ACCESS_KEY_ID="xxx"
	export AWS_SECRET_ACCESS_KEY="xxx"

	docker run -it --rm -p 4723:4723 -v ${PWD}/example/genycloud/aws.json:/home/androidusr/genymotion_template/aws.json -e DEVICE_TYPE=geny_aws -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e GENY_SAAS_PASS=${AWS_SECRET_ACCESS_KEY} -e APPIUM=true budtmo/docker-android:genymotion
	```

	The deployed device(s) are automatically connected with adb inside docker container. Stopping the emulator will remove all deployed device(s) on Genymotion SaaS and user will be logged out at the end. As destroying all deployed ressources take time in AWS (it takes around 3 min), you need to specify the waiting time on docker stop

	```
	docker stop --time=180 android-container
	```


[<- BACK TO README](../README.md)

---

### Documentations/USE CASE APPIUM (documentations/USE_CASE_APPIUM.md)

Run Appium Server
-----------------

Appium is automation test framework to test mobile website and mobile application, including Android. To be able to use Appium, you need to run Appium-Server. You run Appium-Server inside docker-android container by ***opening port 4723*** and ***passing an environment variable APPIUM=true***.

docker run -d -p 6080:6080 -p 4723:4723 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true -e APPIUM=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0

text
### Additional parameters to Appium Server

The user can pass the additional parameter to Appium Server through environment variable ***APPIUM_ADDITIONAL_ARGS***. Please check [this page](http://appium.io/docs/en/2.0/cli/args/) for possible arguments that can be passed to Appium 2.x.

### Connect to Selenium Grid 4.x

The user can connect docker-android that contains Appium 2.x to Selenium Grid 4.x without any additional configurations / changes in docker-android project. Please check [this page](http://appium.io/docs/en/2.0/guides/grid/) for detail information 


[<- BACK TO README](../README.md)

---

### Documentations/USE CASE BUILD ANDROID PROJECT (documentations/USE_CASE_BUILD_ANDROID_PROJECT.md)

Build Android project
---------------------

Docker-Android can be used for building Android project and executing its unit test. This following steps will illustrate how to build Android project:

1. Clone [this sample test project](https://github.com/android/testing-samples).

    ```
    git clone [email protected]:android/testing-samples.git
    ```

2. Build the project

    ```
    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"
    ```


[<- BACK TO README](../README.md)

---

### Documentations/USE CASE CLOUD (documentations/USE_CASE_CLOUD.md)

Azure
-----

Make sure that the nodes, pods, containers for your emulators are generated within a **VM** of series **Dv3** or **Ev3**.
Reference: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nested-virtualization

AWS
-----
Make sure that containers for your emulators are generated within a EC2 Bare Metal Instance(i3.metal)
Reference: https://aws.amazon.com/jp/blogs/aws/new-amazon-ec2-bare-metal-instances-with-direct-access-to-hardware/

Google Cloud (GCE)
------------------
Make sure your instances for your emulators have Nested Virtualization enabled
Reference: https://cloud.google.com/compute/docs/instances/enable-nested-virtualization-vm-instances


[<- BACK TO README](../README.md)

---

### Documentations/USE CASE CONTROL EMULATOR (documentations/USE_CASE_CONTROL_EMULATOR.md)

Control emulator from host machine
----------------------------------

1. Open port 5554 and 5555 while running docker-android container
	 ```
	 docker run ... -p 5554:5554 -p 5555:5555 ...
	 ```

2. Connect emulator inside docker-android container with host adb
	 ```
	 adb connect <docker-machine-ip-address>:5555
	 ```




[<- BACK TO README](../README.md)

---

### Documentations/USE CASE JENKINS (documentations/USE_CASE_JENKINS.md)

Jenkins
-------

Following Jenkins plug-ins supports Docker-Android to optimize your work.

1. Live preview: [budtmo/jenkins-plugin-vncviewer-docker-container](https://github.com/budtmo/vncviewer-docker-container-plugin)


[<- BACK TO README](../README.md)

---

### Documentations/USE CASE SMS (documentations/USE_CASE_SMS.md)

SMS
---

- Example by using adb

	 ```bash
	 docker exec -it android-container adb emu sms send  <message>
	 ```

- The user can also integrate it inside project using adb library.




[<- BACK TO README](../README.md)

---

### Documentations/USER BEHAVIOR ANALYTICS (documentations/USER_BEHAVIOR_ANALYTICS.md)

# Docker-Android's Anonymous Aggregate User Behavior Analytics
Docker-Android has begun gathering anonymous aggregate user behavior analytics and reporting these to Google Sheets through Google Forms API (Google Form ID: 1FAIpQLSdrKWQdMh6Nt8v8NQdYvTIntohebAgqWCpXT3T9NofAoxcpkw). You are notified about this when you start Docker-Android.

## Why?
We don't have direct communication with its users nor time resources to ask directly for their feedback. As a result, we now use anonymous aggregate user behavior analytics to help us understand how Docker-Android is being used, the most common used features based on how, where and when people use it. With this information we can prioritize some features over other ones.

## What?
Docker-Android's Sheets record some shared information for every event:

* Date and time when Docker-Android started
* User (it will collect the information about Release Version of Machine), e.g. Linux-5.4.0-146-generic-x86_64-with-glibc2.29_#163-Ubuntu_SMP_Fri_Mar_17_18:26:02_UTC_2023. This does not allow us to track individual users but does enable us to accurately measure user counts
* City (the information come from https://ipinfo.io)
* Region (the information come from https://ipinfo.io)
* Country (the information come from https://ipinfo.io)
* Release version of Docker-Android
* Appium (Whether user use Appium or not - The possible value will be "true" or "false")
* Appium Additional Arguments
* Web-Log (Whether user use Web-Log feature or not - The possible value will be "true" or "false")
* Web-Vnc (Whether user use Web-Vnc feature or not - The possible value will be "true" or "false")
* Screen-Resolution
* Device Type (Which docker image is used - The possible value will be "emulator" or "geny_cloud" or "geny_aws")
* Emulator Device (Which device profile and skin is used if the user use device_type "emulator")
* Emulator Android Version (Which Android version is used if the user use device_type "emulator"
* Emulator No-Skin feature (Whether user use no-skin feature or not - The possible value will be "true" or "false")
* Emulator Data Partition
* Emulator Additional Arguments

With the recorded information, it is not possible for us to match any particular real user.

## When/Where?
Docker-Android's user behavior analytics are sent throughout Docker-Android's execution to Google Sheets through Google Forms API over HTTPS.

## Who?
Docker-Android's analytics are accessible to Docker-Android's current maintainers. Contact [@budtmo](https://github.com/budtmo) if you are a maintainer and need access.

## How?
The code is viewable in [these scripts](../cli/src/device).

## Opting out before starting Docker-Android
Docker-Android analytics helps us, maintainers and leaving it on is appreciated. However, if you want to opt out and not send any information, you can do this by using passing environment variable USER_BEHAVIOR_ANALYTICS=false to the Docker container.

## Disclaimer
This document and the implementation are based on the great idea implemented by [Homebrew](https://github.com/Homebrew/brew/blob/master/docs/Analytics.md)


[<- BACK TO LICENSE](../LICENSE.md)

---

### Documentations/Pro Example/Node.Json (documentations/pro-example/node.json)

[
    {
      "appium_url": "http://xx.xx.xx.xx:4723",
      "capability_platform": "android",
      "capability_platform_version": "11.0",
      "capability_device_name": "samsung_galaxy_s6_11.0",
      "capability_automation_name": "UIAutomator2"
    },
    {
      "appium_url": "http://xx.xx.xx.xx:4724",
      "capability_platform": "android",
      "capability_platform_version": "10.0",
      "capability_device_name": "nexus_5_10.0",
      "capability_automation_name": "UIAutomator2"
    }
]

---

### Example/Genymotion/Aws.Json (example/genymotion/aws.json)

[
	{
		"name": "device1",
		"region": "eu-west-1",
		"ami": "ami-68d78411",
		"instance_type": "t2.small",
		"ingress_rules": [
			{
				"from_port": 22,
				"to_port": 22,
				"protocol": "tcp",
				"cidr_blocks": ["0.0.0.0/0"]
			},
			{
				"from_port": 80,
				"to_port": 80,
				"protocol": "tcp",
				"cidr_blocks": ["0.0.0.0/0"]
			},
			{
				"from_port": 443,
				"to_port": 443,
				"protocol": "tcp",
				"cidr_blocks": ["0.0.0.0/0"]
			},
			{
				"from_port": 51000,
				"to_port": 51100,
				"protocol": "tcp",
				"cidr_blocks": ["0.0.0.0/0"]
			},
			{
				"from_port": 51000,
				"to_port": 51100,
				"protocol": "udp",
				"cidr_blocks": ["0.0.0.0/0"]
			}
		],
		"egress_rules": [
			{
				"from_port": 0,
				"to_port": 65535,
				"protocol": "udp",
				"cidr_blocks": ["0.0.0.0/0"]
			}
		]
	}, 
	{
		"name": "device2",
		"region": "eu-west-1",
		"ami": "ami-68d78411",
		"instance_type": "t2.small",
		"security_group": "<your_existing_sg>"
	}
]

---

### Example/Genymotion/Saas.Json (example/genymotion/saas.json)

[
    {
      "name": "SamsungS7V6",
      "template": "a2a0c86c-7572-45fe-98d0-66f8efed9fa0",
      "local_port": 51345
    },
    {
      "template": "80a67ae9-430c-4824-a386-befbb19518b9"
    }
]

---

### Mixins/Configs/Devices/Skins/README (mixins/configs/devices/skins/README.md)

Sources
--------

The Emulator skins are taken from [Android Studio IDE](https://developer.android.com/studio) and [Samsung Developer Website](https://developer.samsung.com/home.do)

---

### .Github/Dependabot.Yml (.github/dependabot.yml)

version: 2
updates:
- package-ecosystem: docker
  directory: "/docker"
  schedule:
    interval: daily
    time: '01:00'
    timezone: "Europe/Berlin"
  commit-message:
    prefix: "[docker] "
  target-branch: "master"
  open-pull-requests-limit: 10
  labels:
    - "dependabot"
    - "docker"
  reviewers:
    - "budtmo"

- package-ecosystem: github-actions
  directory: "/"
  schedule:
    interval: daily
    time: '01:00'
    timezone: "Europe/Berlin"
  commit-message:
    prefix: "[github-action] "
  target-branch: "master"
  open-pull-requests-limit: 10
  labels:
    - "dependabot"
    - "github-action"
  reviewers:
    - "budtmo"

- package-ecosystem: pip
  directory: "/"
  schedule:
    interval: daily
    time: '01:00'
    timezone: "Europe/Berlin"
  commit-message:
    prefix: "[pip] "
  target-branch: "master"
  open-pull-requests-limit: 10
  labels:
    - "dependabot"
    - "pip"
  reviewers:
    - "budtmo"

---

### .Github/PULL REQUEST TEMPLATE (.github/PULL_REQUEST_TEMPLATE.md)

### Types of changes
_Put an `x` in the boxes that apply_

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)

### Purpose of changes

---

### .Github/ISSUE TEMPLATE/Bug.Yml (.github/ISSUE_TEMPLATE/bug.yml)

name: ๐Ÿ› Bug Report
title: "[๐Ÿ› Bug ]: "
labels: [bug]
body:
  - type: input
    id: operating-system
    attributes:
      label: Operating System
      placeholder: e.g. OSX Yosemite / Ubuntu 20.04 / Windows 10 etc
    validations:
      required: true
  - type: input
    id: docker-image
    attributes:
      label: Docker Image
      placeholder: e.g. budtmo/docker-android:emulator_10.0_v2.0 / budtmo/docker-android:genymotion_v2.0 etc
    validations:
      required: true
  - type: textarea
    id: expected-behaviour
    attributes:
      label: Expected behaviour
        What behaviour that you expected?
    validations:
      required: true
  - type: textarea
    id: actual-behaviour
    attributes:
      label: Actual behaviour
        What is the actual behaviour?
    validations:
      required: true
  - type: textarea
    id: logs
    attributes:
      label: Logs
        Please provide logs here
    validations:
      required: false

---

### .Github/ISSUE TEMPLATE/Bug Pro Version.Yml (.github/ISSUE_TEMPLATE/bug_pro_version.yml)

name: ๐Ÿ› [Pro version] Bug Report
title: "[๐Ÿ› PRO | Bug ]: "
labels: [bug, pro]
body:
  - type: input
    id: operating-system
    attributes:
      label: Operating System
      placeholder: e.g. OSX Yosemite / Ubuntu 20.04 / Windows 10 etc
    validations:
      required: true
  - type: input
    id: docker-image
    attributes:
      label: Docker Image
      placeholder: e.g. budtmo/docker-android-pro:emulator_10.0_v2.0 / budtmo/docker-android-pro:emulator_headless_10.0_v2.0 etc
    validations:
      required: true
  - type: textarea
    id: expected-behaviour
    attributes:
      label: Expected behaviour
        What behaviour that you expected?
    validations:
      required: true
  - type: textarea
    id: actual-behaviour
    attributes:
      label: Actual behaviour
        What is the actual behaviour?
    validations:
      required: true
  - type: textarea
    id: logs
    attributes:
      label: Logs
        Please provide logs here
    validations:
      required: false

---

### .Github/ISSUE TEMPLATE/Config.Yml (.github/ISSUE_TEMPLATE/config.yml)

blank_issues_enabled: false
contact_links:
  - name: ๐Ÿ“– Docker-Android Documentation
    url: https://github.com/budtmo/docker-android
    about: Please read the whole project README before filling out an issue.

---

### .Github/ISSUE TEMPLATE/Feature.Yml (.github/ISSUE_TEMPLATE/feature.yml)

name: ๐Ÿš€ Feature Request
title: "[๐Ÿš€ Feature Request ]: "
labels: [feature-request]
body:
  - type: textarea
    id: idea
    attributes:
      label: Idea
        What is the idea that you want to share to improve the project?
    validations:
      required: true
  - type: textarea
    id: problem
    attributes:
      label: Probelm to solve
        What is the problem that you want to solve with requested feature?
    validations:
      required: true
  - type: textarea
    id: Note
    attributes:
      label: Additional Note
        Please share any additional information here if needed
    validations:
      required: false

---

### .Github/Workflows/Release.Yml (.github/workflows/release.yml)

name: Release

on:
  push:
    tags:
      - 'v*.*-*'

jobs:
  run_test:
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        python-version: ["3.8"]
    steps:
    - name: Checkout the repo
      uses: actions/checkout@v7

    - name: Run unit-test
      run: script -e -c "./app.sh test emulator test 11.0 && sudo mv tmp/* ."

  release_base:
    runs-on: ubuntu-24.04
    needs: run_test
    steps:
    - name: Checkout the repo
      uses: actions/checkout@v7

    - name: Get release version
      run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

    - name: Build and push base image (${RELEASE_VERSION})
      run: |
        docker login -u=${{secrets.DOCKER_USERNAME}} -p=${{secrets.DOCKER_PASSWORD}}
        ./app.sh push base ${RELEASE_VERSION}
        docker logout

  release_emulator:
    runs-on: ubuntu-24.04
    needs: release_base
    strategy:
      matrix:
        android: ["9.0", "10.0", "11.0", "12.0", "13.0", "14.0"]
    steps:
    - name: Checkout the repo
      uses: actions/checkout@v7

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4

    - name: Get release version
      run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
    
    - name: Set up extension
      run: |
        echo "${{ secrets.extension }}" > extension.sh
        chmod 700 extension.sh
      shell: bash

    - name: Build and push emulator image ${{ matrix.android }} (${RELEASE_VERSION})
      run: |
        docker login -u=${{secrets.DOCKER_USERNAME}} -p=${{secrets.DOCKER_PASSWORD}}
        ./app.sh push emulator ${RELEASE_VERSION} ${{ matrix.android }}
        docker logout

  release_genymotion:
    runs-on: ubuntu-24.04
    needs: release_base
    steps:
    - name: Checkout the repo
      uses: actions/checkout@v7

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4

    - name: Get release version
      run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

    - name: Set up extension
      run: |
        echo "${{ secrets.extension }}" > extension.sh
        chmod 700 extension.sh
      shell: bash

    - name: Build and push genymotion image (${RELEASE_VERSION})
      run: |
        docker login -u=${{secrets.DOCKER_USERNAME}} -p=${{secrets.DOCKER_PASSWORD}}
        ./app.sh push genymotion ${RELEASE_VERSION}
        docker logout

---

### .Github/Workflows/Test On Demand.Yml (.github/workflows/test-on-demand.yml)

name: Run Test on Demand

on:
  workflow_dispatch:

jobs:
  build_and_test:
    runs-on: ubuntu-24.04
    steps:
    - name: Checkout the repo
      uses: actions/checkout@v7

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4

    - name: Set up extension
      run: |
        echo "${{ secrets.extension }}" > extension.sh
        chmod 700 extension.sh
      shell: bash

    - name: Build base image
      run: script -e -c "./app.sh build base test"

    - name: Build sample image
      run: script -e -c "./app.sh build emulator test 11.0"

    - name: Run unit-test
      run: script -e -c "./app.sh test emulator test 11.0 && sudo mv tmp/* ."

    - name: Publish test result
      run: bash <(curl -s https://codecov.io/bash)

---

### .Github/Workflows/Test.Yml (.github/workflows/test.yml)

name: Run Test

on:
  push:
    branches:
      - master

jobs:
  build_and_test:
    runs-on: ubuntu-24.04
    if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.actor == 'budtmo'
    steps:
    - name: Checkout the repo
      uses: actions/checkout@v7

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v4

    - name: Set up extension
      run: |
        echo "${{ secrets.extension }}" > extension.sh
        chmod 700 extension.sh
      shell: bash

    - name: Build base image
      run: script -e -c "./app.sh build base test"

    - name: Build sample image
      run: script -e -c "./app.sh build emulator test 11.0"

    - name: Run unit-test
      run: script -e -c "./app.sh test emulator test 11.0 && sudo mv tmp/* ."

    - name: Publish test result
      run: bash <(curl -s https://codecov.io/bash)

---