All Projects → fastphat → Android Container

fastphat / Android Container

Licence: apache-2.0
Run E2E Android Testing with Docker Container

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Android Container

Androidsdk
🐳 Full-fledged Android SDK Docker Image
Stars: ✭ 776 (+1041.18%)
Mutual labels:  gradle, docker-container
Materialstyleddialogs
A library that shows a beautiful and customizable Material-based dialog with header. API 14+ required.
Stars: ✭ 1,139 (+1575%)
Mutual labels:  gradle
Tabbychat 2
Successor to TabbyChat
Stars: ✭ 53 (-22.06%)
Mutual labels:  gradle
Docker Vault
Docker Container for Hashicorp's Vault
Stars: ✭ 60 (-11.76%)
Mutual labels:  docker-container
Gradle S3 Build Cache
An AWS S3 Gradle build cache implementation
Stars: ✭ 54 (-20.59%)
Mutual labels:  gradle
Fetch
The best file downloader library for Android
Stars: ✭ 1,124 (+1552.94%)
Mutual labels:  gradle
Auto Manifest
Generates AndroidManifest.xml in simple libraries so that you don't have to
Stars: ✭ 51 (-25%)
Mutual labels:  gradle
Android Camera2 Library
Library to use Android Camera2 api easily.
Stars: ✭ 66 (-2.94%)
Mutual labels:  gradle
Habito
Simple habit tracker app for Android
Stars: ✭ 65 (-4.41%)
Mutual labels:  gradle
Ros2 java
Java and Android bindings for ROS2
Stars: ✭ 60 (-11.76%)
Mutual labels:  gradle
Spongeforge
A Forge mod that implements SpongeAPI
Stars: ✭ 1,106 (+1526.47%)
Mutual labels:  gradle
S Mvp
🔥🔥优化版MVP,使用注解泛型简化代码编写,使用模块化协议方便维护,APT过程使用注解解析器利用JavaPoet🌝完成重复模块的编写,利用ASpect+GradlePlugin 完成横向AOP编程+Javassist动态字节码注入+Tinker实现热修复+Retrofit实现优雅网络操作+RxJava轻松玩转数据处理
Stars: ✭ 1,095 (+1510.29%)
Mutual labels:  gradle
Nodebb Webview
NodeBB WebView for Android
Stars: ✭ 64 (-5.88%)
Mutual labels:  gradle
Androidgradleplugincompat
android gradle plugin兼容库
Stars: ✭ 54 (-20.59%)
Mutual labels:  gradle
Microservices Example
Example of a microservices architecture on the modern stack of Java technologies
Stars: ✭ 66 (-2.94%)
Mutual labels:  gradle
Business Search App Java
Showcases object oriented programming in Java, Java Swing, Kotlin, and Android
Stars: ✭ 53 (-22.06%)
Mutual labels:  gradle
Restfeel
RESTFeel: 一个企业级的API管理&测试平台。RESTFeel帮助你设计、开发、测试您的API。
Stars: ✭ 59 (-13.24%)
Mutual labels:  gradle
Aws Cli Docker
Docker container with the AWS CLI
Stars: ✭ 62 (-8.82%)
Mutual labels:  docker-container
Version Checker Gradle Lint
Warning on new versions available even when using Kotlin-DSL plugin.
Stars: ✭ 68 (+0%)
Mutual labels:  gradle
Poco
Poco will help you to organise and manage Docker, Docker-Compose, Kubernetes, Openshift projects of any complexity using simple YAML config files to shorten the route from finding your project to initialising it in your local environment.
Stars: ✭ 66 (-2.94%)
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].