All Projects → phatnhse → android-container

phatnhse / android-container

Licence: Apache-2.0 license
Run E2E Android Testing with Docker Container

Programming Languages

shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to android-container

Spring Boot K8s Hpa
Autoscaling Spring Boot with the Horizontal Pod Autoscaler and custom metrics on Kubernetes
Stars: ✭ 250 (+147.52%)
Mutual labels:  docker-container
alpine-qbittorrent-openvpn
qBittorrent docker container with OpenVPN client running as unprivileged user on alpine linux
Stars: ✭ 230 (+127.72%)
Mutual labels:  docker-container
docker-compose-laravel
A Docker Compose setup for Laravel projects.
Stars: ✭ 23 (-77.23%)
Mutual labels:  docker-container
docker-collectd
Collectd within a Docker image
Stars: ✭ 59 (-41.58%)
Mutual labels:  docker-container
jenkins-ecs-deployment
Deploy docker containers to AWS ECS/ECR via Jenkins
Stars: ✭ 20 (-80.2%)
Mutual labels:  docker-container
docker-pivpn
A secure docker container that sets up PiVPN in a virtual environment.
Stars: ✭ 82 (-18.81%)
Mutual labels:  docker-container
Iotwifi
Raspberry Pi (arm) wifi configuration container. Configure and control wifi connectivity with a JSON based REST api.
Stars: ✭ 236 (+133.66%)
Mutual labels:  docker-container
mirror-http-server
A dummy HTTP server that responds whatever you told it to
Stars: ✭ 35 (-65.35%)
Mutual labels:  docker-container
docker-tutorial
2DAW Tutorial de Docker para el desarrollo avanzado de código y despliegue de aplicaciones con distintos ejemplos prácticos. Aprende a usar Docker Files y Docker Compose.
Stars: ✭ 26 (-74.26%)
Mutual labels:  docker-container
nanoinit
A small, proper, init process for docker containers.
Stars: ✭ 43 (-57.43%)
Mutual labels:  docker-container
docker-chromium
Docker container with Chromium desktop and a Web VNC client allowing you to run Chromium on any server you have
Stars: ✭ 64 (-36.63%)
Mutual labels:  docker-container
docker-ps3netsrv
Alpine based docker image for ps3netsrv (with arm compatibility). Built with the latest ps3netsrv binaries from aldostools (built from master), latest = ps3netsrv v20220813, edge = ps3netsrv v20220813
Stars: ✭ 55 (-45.54%)
Mutual labels:  docker-container
ModelicaInAction
Modelica In Action
Stars: ✭ 39 (-61.39%)
Mutual labels:  docker-container
LID-DS
LID-DS is an intrusion detection data simulation framework.
Stars: ✭ 32 (-68.32%)
Mutual labels:  docker-container
docker-iot-dashboard
A complete IoT server for LoRaWAN IoT projects: node-red + influxdb + grafana + ssl + let's encrypt using docker-compose.
Stars: ✭ 79 (-21.78%)
Mutual labels:  docker-container
Fluentdocker
Commands, Services and Fluent API for docker, docker-compose & docker-machine, for win/mac/linux and native docker in c#
Stars: ✭ 245 (+142.57%)
Mutual labels:  docker-container
play-docker-aws-tutorial
101 tutorial: How to deploy Play application to Amazon Lightsail (AWS) using Docker
Stars: ✭ 25 (-75.25%)
Mutual labels:  docker-container
docker-ansible
Alpine-based multistage-build version of Ansible for reproducible usage in CI
Stars: ✭ 168 (+66.34%)
Mutual labels:  docker-container
docker-nginx-mainline
Devilbox's Nginx mainline (based on official Nginx Docker) [multi-arch]
Stars: ✭ 15 (-85.15%)
Mutual labels:  docker-container
pyrex
Seamless container setup for developing with OpenEmbedded/Yocto Project
Stars: ✭ 27 (-73.27%)
Mutual labels:  docker-container

Build a Lightweight Docker Container For Android Testing

Docker Hub Docker Stars Docker Pulls Build Status

Goals

  • No Android Studio/GUI applications required.
  • Android emulator runs on a Docker container.
  • Accelerates build speed and stabilize testing process, especially UI Tests.
  • Performance boost with Gradle dependencies and distribution caching.

Release notes

Change logs can be found here

Remarks

  • No additional ARG(s) need to be provided in order to run this image.
  • Linux only. MacOS/Window or any solution which uses VirtualBox to embed Docker can't run x86 emulator because nested virtualization is yet to support. In the contrary, ARM CPU is host machine independent, which can run anywhere, however it was deprecated and extremely slow to boot.
  • In the scope of this repo, x86 Emulator is chosen as default startup emulator since it is 10x faster than ARM. KVM & nested virtualization will be needed so Linux-based OS as host system is required, especially if you want to build a CI machine with this image.

Quick start

We'll try to build and run E2E testing with project Sunflower.

Step 1: Build image with name & tag: android-container:sunflower

docker build -t android-container:sunflower .

Step 2: Clone and go to top level directory of sunflower

git clone https://github.com/android/sunflower && cd sunflower/

Step 3: Run with privileged permission in order to boot emulator on the container, then run gradle tasks (build project and run test suite)

docker run --privileged -it \
--rm -v $PWD:/data -v gradle-cache:/cache android-container:sunflower \
bash -c '. /start.sh && /data/gradlew test -p /data'

If you want to run UI test, make sure KVM is enable and run this gradle task connectedAndroidTest (See Emulator)

/data/gradlew test connectedAndroidTest -p /data

Android SDK Packages Management

These following components will be automatically downloaded and installed by default:

# adb    
platform-tools

# avdmanager and sdkmanager
tools 

# emulator toolkit
emulator

# build tools
platforms;android:30

# android virtual device
system-images;android:30;google_apis;x86 

To install additional components, specific them with ANDROID_SDK_PACKGES_EXTRA when build with Dockerfile. Remember to add single space between components. Some typical filters:

ANDROID_SDK_PACKAGES_EXTRA="ndk;21.0.6113669 cmake;3.10.2.4988404"

To get full list of installed components, run:

sdkmanager  --list | awk '/Installed packages/{flag=1; next} /Available Packages/{flag=0} flag' | awk '{ print $1  }'

The output will look like this:

Path
-------
build-tools;27.0.3
build-tools;28.0.3
cmake;3.10.2.4988404
emulator
extras;android;m2repository
extras;google;m2repository
ndk-bundle
ndk;21.0.6113669
patcher;v4
platform-tools
...

Gradle

You can either execute Gradle Wrapper or Local Installation but first option is more preferable

In a nutshell you gain the following benefits:

  • Standardizes a project on a given Gradle version, leading to more reliable and robust builds.
  • Provisioning a new Gradle version to different users and execution environment (e.g. IDEs or Continuous Integration servers) is as simple as changing the Wrapper definition.

Get the idea of Gradle Wrapper

Gradle wrapper is a script that allow you to run the build with predefined version and settings. The generated Wrapper properties file, gradle/wrapper/gradle-wrapper.properties, stores the information about the Gradle distribution.

gradle wrapper properties

Wanna use newer version? Grab one at here and update distributionUrl accordingly.

Speed up build with Gradle Caching

By default, all files downloaded under docker container doesn't persist if the container is removed. Therefore, they will be re-downloaded in every build. However, Docker offers a solution called Volume. It is typically directories or files on host filesystem and can be accessible from both container and host machine. You just need to define a location where the volume references to and let it take care the rest. Consider this following script and image:

ENV GRADLE_USER_HOME=/cache
VOLUME $GRADLE_USER_HOME


You can always check where the volumes are located and how they work:

  • On Macos:
~/Library/Containers/com.docker.docker/Data/vms/0/tty
  • On Linux:
~/var/lib/docker/volumes
  • To list all volumes are being use:
docker volume ls
  • To get all properties of a volume:
docker volume inspect [volume_id]

Non-cached vs cached gradle dependencies

In some circumstances, you will see this one is huge improvement, especially when a project has used ton of dependencies. Let's see the different between cached and non-cached gradle for Sunflower project.

BUILD SUCCESSFULL in 4m 25s
...
...
BUILD SUCCESSFULL in 55s 

build time comparison

Android Emulator

If you're familiar with Android Studio, you definitely experience this warning when booting ARM emulators. They were old and deprecated since Android SDK 25. In the contrary, x86 emulators are 10x faster, but it needs hardware acceleration to run (HAXM on Mac & Windows, QEMU on Linux). On Docker, you will also need Nested Virtualization, which is not available on Virtual Box. So Linux-based OS is recommended in order to make it compatible with this image.

Check the availability of running android emulator in docker container

The script below simply checks if kvm & nested virtualization is supported.

function check_kvm() {
    cpu_support_hardware_acceleration=$(grep -cw ".*\(vmx\|svm\).*" /proc/cpuinfo)
    kvm_support=$(kvm-ok)
    if [ "$cpu_support_hardware_acceleration" != 0 ] && [ "$kvm_support" != *"NOT"* ]; then
      echo 1
    else
      echo 0
    fi
}

Reduce flaky tests

You can turn off following animations by using adb shell ( these can be found in developer options )

  • Window animation scale
  • Transition animation scale
  • Animation duration scale
function disable_animation() {
  adb shell "settings put global window_animation_scale 0.0"
  adb shell "settings put global transition_animation_scale 0.0"
  adb shell "settings put global animator_duration_scale 0.0"
}

You can also disable keyboard or customize default locale language

adb shell settings put secure show_ime_with_hard_keyboard 0 
adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE EN

Emulator startup options

Unlike adb, you can only specify emulator options when starting it, not later on. Consider following command & options:

emulator -avd ${EMULATOR_NAME} -no-window -no-boot-anim -wipe-data -no-snapshot -gpu off -accel auto -memory 2048 -skin 1440x2880
Option Description
-no-boot-anim Disable the boot animation
-acel auto Determine automatically if acceleration is supported and use it when possible
-no-window -gpu off This option is useful when running the emulator on headless servers.
You'll still be able to access the emulator through adb or the console
-skin 1440x2880 In case you want the screen has more room, especially with list of items.
Use it at your risk, it would be better to support different screen sizes
-memory 2048 Building CI Server with 4GB physical RAM, why not?
-wipe-data Delete user data and fresh start emulator
-no-snapshot Start app from initial state and delete snapshot data when emulator is closed

License

Released under the Apache License.

Read the LICENSE for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].