Building Flutter Android Apps Using Docker: A Guide

Winston Ma
2 min readSep 30, 2022

Building Flutter Android apps using Docker provides a convenient and efficient way to streamline the development process, especially when working with Jenkins. In this guide, I will walk you through the steps to build your Flutter Android apps using a Docker environment. By leveraging Docker, you can create a reproducible image for different projects without the need to install tools directly in Jenkins.

In short, I built a Docker (gist) environment so I can recreate the image for different projects. This dockerfile would only create a building envoirnment.

Building of Dockerfile

This is the design in a nutshell. The docker image should be able to build flutter android source code without installing anything on the host machine.

Docker environment

Choose the base image

Since I couldn’t find a Dockerfile

  1. Build theflutter image from Ubuntu image, or
  2. Build the flutter image from Flutter image

Luckily I could find reliable flutter image creater Cirrus CI. As they update the Flutter image from time to time (Dockerhub) this is a realiable source.

However after running `flutter doctor` it told me that the system lack the android build tool needed. Therefore I would need to install the docker image

Install needed packages

Next I would need to install the Android toolchain, chrome. Luckily I found a sample Dockerfile, provided by flutter, that installs all the support tools Flutter needed. However this image is based on Ubuntu and thus it would not have Flutter.

In order to get Flutter and tools together in one image, I just need to take this Dockerfile and replace with Ubuntu base image with Cirrus CI’s image.

# FROM ubuntu:bionic@sha256:eb1392bbdde63147bc2b4ff1a4053dcfe6d15e4dfd3cce29e9b9f52a4f88bc74
FROM cirrusci/flutter

Include Sample Project

The following lines would create and build the flutter sample project:

WORKDIR /root
RUN flutter create .
RUN flutter build apk --release

After adding the sample project it fails because the default java version is incorrect. After checking the image it seems that the value of JAVA_HOME is not correctly assigned. Therefore I added the following line in Dockerfile:

# ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

Then the build process is success. Next step all I need is to obtain the built apk from the Docker image. For this part please reference the README.md inside gist.

--

--