Building android project with Docker and Walter, independent from the specific platform

 Difficulty of building android project

I think it’s too complicated for me to building .apk file from some android project. When building android project on some CI system away from your Android studio, I always feel confused about “What package do I need to build this android project?”. For example,

 Build android project with Docker

During I suffered from building a android project, I found the cool project which uses docker for building .apk files. The Dockerfile inherits gfx/docker-android-project, which is installed dependent packages to a build android project. By building project inside Docker container, once you build a docker image for android project, you can build the android project regardless of a SDK or some package dependencies.

Besides, I forked the idea to ainoya/docker-android-project and modify to install the SDK components you need on the project-side with using ONBUILD syntax of Dockerfile.

# Install Android SDK components

ONBUILD COPY android_sdk_components.env /android_sdk_components.env
ONBUILD RUN echo y | android update sdk --no-ui --all --filter "$(cat /android_sdk_components.env)"

 Use case

Here, I describe some use case which builds a android project with using ainoya/docker-android-project.

Dockerfile in the root directory of my android project is described below;



ENV PROJECT /project

RUN echo "sdk.dir=$ANDROID_HOME" >
RUN ./gradlew --stacktrace androidDependencies

CMD ./gradlew --stacktrace build

In addition to Dockerfile, I prepare android_sdk_components.env that described the package needed in same directory of Dockerfile.



Then, construct the docker image for building .apk with docker build command.

docker build -t your-android-project-build:latest .

Once you prepared the image, you can build your android project everywhere run with docker run command like below;

docker run -t -v $(pwd)/app:/project/app your-android-project-build:latest ./gradlew clean assembleRelease

As using -v option to get .apk file was built inside container, you can get the build archives app/build/* directory.

 Automate distribution flow of you app with walter, a build-pipeline tool

Thus, you get the environment building a android project with using docker, but you may have to do other task such as,

Usually, these flow is configured in Jenkins, Travis, or other CI platforms through their GUI. But as I said before, Didn’t we want to describe these distribution flow of the application? Moreover, didn’t you think that you want to distribute apps from the local machine? In such a case, walter-cd/walter is very convenient to describe the distribution workflow and execute the workflow independent from the specific platform.

For example, I show the workflow configuration described for executing it with using walter.


    type: slack
    channel: release_channel
    username: release-bot
    - name: start up
      command: echo 'Starting build workflow..'
      report_full_output: true
            - name: changelog
              command: |
                  echo '----------------'
                  git --no-pager log -n 1
                  echo '----------------'
              report_full_output: true
            - name: build apk from project
              command: |
                  docker run -t -v $(pwd)/app:/project/app yourapp-android-build:latest ./gradlew clean assembleRelease
    - name: distribute apk file
      command: |
          BIN_ID=$(gdrive upload --file yourApp/app/build/outputs/apk/app-release.apk | grep Id: | cut -f2 -d' ')
          gdrive share -i ${BIN_ID} > /dev/null
          echo '----------------'
          echo 'Finished build apk successfully'
          echo '<! channel > :  Please download from url below'
          gdrive url -d -i ${BIN_ID}
          echo '----------------'
      report_full_output: true

walter is written in Golang, and you can download cross-platform binary from GitHub Releases. Also, brew install walter command is available if you’d like to run walter on Mac.

If you want to know more about walter, please read in the walter-cd/walter repository.

In this example, the distribution workflow of android project is consist of these steps;

  1. Build a apk from android project with docker as the way I explained
  2. Upload the apk file to Google Drive with gdrive command
  3. Notify the download url of the uploaded apk file to Slack

distribution flow

Once you configured these settings, you only run the command ./walter -c pipeline.yml to execute distribution workflow. Also, you don’t have to complex GUI settings of some CI tools anymore.


Now read this

Access Docker API from within container

Nowadays I’m contributing to pool project, which provides the simple http proxy launches docker container on access with commit-id of git repository, to be called even a “Just In Time Container”. At first prototyping, pool provided the... Continue →

Subscribe to Naoki AINOYA

Don’t worry; we hate spam with a passion.
You can unsubscribe with one click.