In this post, we’ll explain how to set up a Flutter Android CI/CD pipeline using Jenkins and Firebase App Distribution.
· Prerequisites
· Install OpenJDK
· Install Flutter Debian / Ubuntu
∘ Install Snap (if not already installed)
∘ Install Flutter
∘ Add Flutter to your PATH
· Setup Android SDK
∘ Install command line tools
∘ Install packages
∘ Flutter Licenses
· Validate Flutter Setup
∘ Flutter Android SDK Path
∘ Run Flutter doctor
· Flutter Jenkins Pipeline CI
∘ Android SDK path
∘ Jenkins Pipeline Setup
· Conclusion
· Troubleshooting
· References
Prerequisites
This is the list of all the prerequisites for this part 1:
- A Jenkins server is already up and running
- A GitHub repository
- Git
- A virtual machine (VM) (with Debian12 as part of this story)
The first part consists of preparing our integration environment. It involves installing and setting up all necessary tools and dependencies on the server. By the end of this story, we will be ready to build and test the Flutter application through Jenkins.
Install OpenJDK
First, run the following command to install Java and then check the version to confirm it has been properly installed.
$ sudo apt install default-jdk
$ java -version

Install Flutter Debian / Ubuntu
Install Snap (if not already installed)
If Snap is not preinstalled for some reason, you can install it using:
$ sudo apt install snapd
After the installation is complete, you can verify that Snap is installed and working correctly by checking its version:
$ snap --version
You should see an output indicating the version of Snap installed:

Install Flutter
You can now use the following command to install Flutter via Snap:
$ sudo snap install flutter --classic
The –classic flag is necessary because Flutter requires classic confinement, granting full system access.
Add Flutter to your PATH
You need to add Flutter SDK in your system PATH. For that add the following line to your ~/.bashrc or ~/.zshrc file:
export PATH="$PATH:/snap/bin"
After adding this line, apply the changes using:
$ source ~/.bashrc
or
$ source ~/.zshrc
Reload the shell by typing the command above.
$ flutter sdk-path
Setup Android SDK
Install command line tools
First, download the commandlinetools zip file for Linux from the following link https://developer.android.com/studio#command-tools
Create directory android-sdk in /opt and unzip the contents of the commandlinetools zip file in /opt/android-sdk
$ mkdir /opt/android-sdk
$ unzip commandlinetools-linux-11076708_latest.zip -d /opt/android-sdk
Then, update tools (all available packages)
$ sudo ./bin/sdkmanager "tools"
Add android-sdk to the PATH
$ vi ~/.bashrc
export ANDROID_SDK="/opt/android-sdk"
export PATH="$PATH:$ANDROID_SDK/cmdline-tools/latest/bin/"
export PATH="$PATH:$ANDROID_SDK/emulator/"
export PATH="$PATH:$ANDROID_SDK/platform-tools/"
$ source ~/.bashrc
To list installed and available packages, use the following syntax:
$ sdkmanager --list
Install packages
Flutter requires the SDK packages (currently at least API level 28) to work properly.
$ sdkmanager --install "platform-tools" "platforms;android-29" "build-tools;29.0.2" "emulator" "platforms;android-28" "build-tools;28.0.3"
Flutter Licenses
This step is important to accept the Android SDK license.
You are required to accept the necessary license for each package you have installed. This step occurs during the installation flow when you install packages from within Android Studio.
If you don’t have Android Studio installed, or it is for a CI server or other headless Linux device without a GUI installed, do the following from the command line:
$ sdkmanager -licenses
Validate Flutter Setup
Flutter Android SDK Path
$ flutter config --android-sdk /opt/android-sdk
Run Flutter doctor
The flutter doctor command validates all components of a complete Flutter environment.
flutter doctor -v

Everything is good now. In this case, we cannot use Android Studio because there is no GUI environment.
Flutter Jenkins Pipeline CI
You are now ready to run your first CI pipeline with Jenkins.
Android SDK path
Go to Jenkins > Manage Jenkins > Configure System > Global Properties > Check Environment Variables and Add the Android SDK path

Jenkins Pipeline Setup
- Login to Jenkins
- Click New Item on Jenkins home page.

The last step is to add the Jenkinsfile to the project root directory. Here is the full content of Jenkinsfile.
pipeline{
agent any
environment {
PATH = "$PATH:/snap/bin"
}
stages {
stage('Checkout code') {
steps {
git branch: 'main', url: 'https://github.com/anicetkeric/flutter_firebase_distribution.git'
}
}
stage('flutter doctor') {
steps {
sh '''
flutter doctor -v
'''
}
}
stage('dependencies') {
steps {
sh '''
flutter pub get
'''
}
}
stage('test') {
steps {
sh '''
flutter test
'''
}
}
stage('Build') {
steps {
sh '''
flutter build apk
'''
}
}
}
post {
always {
echo 'Always message'
}
success {
echo 'Success message'
}
failure {
echo 'Failed :( message'
}
changed {
echo 'Things were different before...'
}
aborted {
echo "Aborted message"
}
}
}
Let’s try:

As we can see, all the steps were completed successfully.
Conclusion
Well done !!. This post shows how to configure a Linux server to build a Flutter Android application using Jenkins.
The complete source code is available on GitHub.
Troubleshooting
- cmdline-tools : could not determine SDK root
https://stackoverflow.com/questions/65262340/cmdline-tools-could-not-determine-sdk-root