Setup a Flutter CI/CD with GitLab CI — Part 2

Building iOS & Android Flutter apps

Roger Tan
Kin + Carta Created
6 min readOct 8, 2019

--

GitLab CI/CD + Flutter illustration cover

In the previous post, we learnt how to setup our GitLab runner on our machine. In part 2, we will install all dependencies needed to build Flutter apps for Android & iOS.

Installing Flutter SDK

Navigate to the Flutter website, download and install Flutter (https://flutter.dev/docs/get-started/install/macos)

In this example, we will install the Flutter SDK at the home directory level (~/flutter). You are free to install at any desired location.

export PATH="$PATH:$HOME/flutter/bin"

Add the above export statement to ~/.bash_profile which will ensure Flutter is available for any future sessions.

Tip: In order to run a Flutter command, you can reload your bash environment by running the following command line:

$ source ~/.bash_profile

When your bash_profile is reloaded. Run the command “flutter doctor” to ensure it works correctly.

$ flutter doctor

Below is an example resulting from “flutter doctor” command line

Installing Android SDK

Android logo

The Android SDK is required to build Android Apps.

There are many ways to install the Android SDK, manually or via Homebrew. In this example, we will use Homebrew as it’s easier to install and to manage dependencies.

Run the following command line to install the Android SDK.

The next step is to install the Java Development Kit (JDK) version 8 which is required to run Android SDK because, at this present time, Android SDK does not support versions higher than 8.

Due to the fact, JDK 8 is presently inaccessible for public use on Oracle’s website, we will install AdoptOpenJDK from a community which builds free JDK binaries.

Run the following command line to install AdoptOpenJDK version 8.

Next step, we need to update the bash_profile which enables Flutter to build Android apps by running the command shown below.

Next step, we need to install the latest Android toolchain with Android 9 (Pie). Run the following command shown below.

Then, to build an Android app, you will need to accept the licenses agreements with Android by running the following command shown below.

At this stage, run flutter doctor to verify that the android toolchain works by running the following command shown below.

You should see a summary without any issues, an example is shown below.

The next step is to install all the dependencies needed for iOS apps.

Note: if you have no write permissions for the folder, you can run the command line shown below to change the owner of the folder to the current shell user.

Installing Xcode (Two ways)

Xcode logo

There are two ways to install the Xcode, via the Mac AppStore or manually.

In this example, we will manually install Xcode via the xcode-install program by running the following command shown below.

Next step, is to install the desired Xcode version by running the following commands.

Installing Cocoapods

CocoaPods logo

CocoaPods is one of most popular dependencies manager for Objective-C and Swift project. In this section, we will install Cocoapods by running the command line below.

Then run flutter doctor command line.

From the resulting of flutter doctor summary, you notice that there are warnings for libmobobiledevice and ideviceinstaller. Ignore this as are not necessary for a CI machine.
Also notice, Cocoapods is installed but not initialized. You can ignore this warning as we have not yet created and ran a Flutter project. From a CI perspective, dependencies will be automatically downloaded for the iOS project.

You’ve just set up a Flutter environment on your CI machine! 🎉

On the next post, we will learn how to set up GitLab CI to test and build Android & iOS apps.

--

--