We are going to use docker to create an environment with Android SDK. The following are the goals to achieve.

  • The environment with Android SDK can be run in a Linux machine.
  • The tests are run for the andoird apps in the container.

The current version of Java inside the container is openjdk version "1.8.0_191". If you want to install Java on your bare metal computer, you can check this page Java Environment Setup, but this is not required.

Install Docker

Please refer to this page Docker Related Resources to install Docker.

Start the Android SDK Container

  • Create folders
    mkdir -p android-sdk/sdk
    mkdir -p android-sdk/android
    mkdir -p android-sdk/gradle
  • Goes to the created folder
    cd android-sdk
  • Pull Android SDK docker image
    docker pull thyrlian/android-sdk
  • Run the necessary steps to install SDK and Android emulator. $ANDROID_HOME in Android SDK Image is /opt/android-sdk
# copy the pre-downloaded SDK to the mounted 'sdk' directory
docker run -it --rm -v $(pwd)/sdk:/sdk thyrlian/android-sdk \
bash -c 'cp -a $ANDROID_HOME/. /sdk'

# Update SDK
docker run -it --rm -v $(pwd)/sdk:/opt/android-sdk thyrlian/android-sdk \
bash -c '/opt/android-sdk/tools/bin/sdkmanager --update'

# Download required SDK packages
docker run -it --rm -v $(pwd)/sdk:/opt/android-sdk thyrlian/android-sdk \
bash -c '/opt/android-sdk/tools/bin/sdkmanager "platform-tools" "platforms;android-29" "emulator"'

# Download emulator system image
docker run -it --rm -v $(pwd)/sdk:/opt/android-sdk thyrlian/android-sdk \
bash -c '/opt/android-sdk/tools/bin/sdkmanager "system-images;android-29;default;x86"'
  • Start the Android SDK container
    docker run -it \
    -v $(pwd)/sdk:/opt/android-sdk:rw \
    -v $(pwd)/android:/root/.android:rw \
    -v $(pwd)/gradle:/root/.gradle:rw \
    -v $APP_FOLDER:/app \
    --workdir /app \
    thyrlian/android-sdk /bin/bash