In the previous articles, we learned how to deploy the Flutter Web app to Firebase Hosting and Amazon S3. And in this tutorial, I will show you how to build and package a Flutter Linux desktop app with Bitrise.Â
Sounds interesting, let’s get started!Â
Flutter Desktop
Desktop support allows you to compile Flutter source code to a native Windows, macOS, or Linux desktop app. Flutter’s desktop support also extends to plugins. You can install existing plugins that support the Windows, macOS, or Linux platforms, or you can create your own.
To compile a desktop application, you must build it on the targeted platform: build a Windows application on Windows, a macOS application on macOS, and a Linux application on Linux.
But in this article, we will go through the Linux application and learn how to build it.Â
Linux requirements
For Linux desktop development, you need the following in addition to the Flutter SDK:
If you have an existing application you can build it using the following commandÂ
flutter build linux
The executable binary can be found in your project under build/linux/<build mode>/bundle/. Alongside your executable binary in the bundle directory there are two directories:
- lib contains the required .so library files
- data contains the application’s data assets, such as fonts or images
And if you want to run the app you can use the following command from the project root:
flutter build linux
‍
In case you don’t have a Flutter app, you can easily use the following command:Â
flutter create flutterlinux
‍
And you will have the Linux folder inside the app directory:
Congratulations! You built and ran the Flutter desktop app for Linux successfully now it’s time to add our project to the CI/CD system.Â
Build a Flutter Desktop for Linux with Bitrise
Assuming you add your project to a source code management system such as GitHub, it’s time to connect your app to Bitrise.Â
Let’s get started!Â
- Login to Bitrise with your account, if you don’t have you can create a free account from here
- In the dashboard, click on Add new app and select Web UI
- Select the app type, click next and choose the repositoryÂ
- Click on auto-add SSH key
‍
- Enter the branch name “i.e main” and click Next
- The scanner step will detect that the project is Flutter and you need to select the suitable stack for your application
- In our case, because it’s a Linux app, we will select Ubuntu VM, and also you can select which machine type you want (Standard, Elite, or EliteXL), then click Next
- Click Confirm and you can skip the App icon for now and click Next
- Click Register a webhook and click to run your first build
- After your first build is finished successfully, you can click on the Workflow editor and add the required steps
- In the Workflow Editor, add a new Script Step (you can rename it as you like) and add the following command to install the prerequisites and enable the flutter desktop for linux app:
#!/usr/bin/env bash
# fail if any commands fail
set -e
# debug log
set -x
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
flutter config --enable-linux-desktop
- Add Flutter Step to run the flutter build command
- Add another Script Step to copy the build folder to the Bitrise Deploy folder to be able to find them in the Artifacts tab
#!/usr/bin/env bash
# fail if any commands fails
set -e
# debug log
set -x
cp -R build/linux $BITRISE_DEPLOY_DIR
‍
- In the Deploy to Bitrise.io - Apps, Logs, Artifacts Step, change the compress option to true to zip the artifacts into one folderÂ
‍
- And the final workflow should be like the following image:
- After the build runs successfully, you can click on the Artifacts tab and download the deploy.zip folder to your Ubuntu machineÂ
- Unzip the folder and open the bundle folder and click on the app executable file The app should be open successfully
Congratulations, you did it! You created your first Flutter Desktop for Linux and built it with your CI/CD workflow on Bitrise.
Thank you for reading this article! If you have any questions or feedback, please reach out to us on Twitter, email, or join the Bitrise Slack to chat with us directly.Â