How to automate Flutter workflow with Makefile?
While developing our Flutter projects, there are many repeatable tasks. This task includes – formatting, running unit tests, cleaning the project, etc. So, in this article, we will see how to automate Flutter workflow with Makefile.
How to automate Flutter workflow with Makefile?
Our IDEs make it easy to perform some of these actions. But we prefer to work with the Command-Line. It means that we either created our scripts or we have to type each command by hand each time. So, Is there a better way to automate this? There is with a Makefile.
The Makefile allows us to create a set of different commands in one file to automate our workflows. With it, we can do three things at once:
- Have one place where we define all the actions we want for our project while at the same time creating relations between them;
- Make it easier to perform those actions with short commands;
- Use this tool in any Flutter project we have.
What is a Makefile?
The make utility automatically determines which pieces of a large program need to be recompiled, and issues command to recompile them. (…) make is not limited to programs. You can use it to describe any task where some files must be updated automatically from others whenever the others change. In the scope of Flutter or Dart development, we can use it to create and chain tasks.
Imagine the following — each time that we need to build our app for iOS and Android we’ll need to do the following steps manually:
- Clean the project.
- Run lint to see if we don’t have any errors
- Run all the tests
- Build the project for mobile with the specified flavor
- Use Fastlane to ship our app to Test-flight and Firebase App Distribution.
By doing this process manually, we have two major drawbacks: first, we will need to run each command by hand every time we need to do a new release, and we will need to verify if each step failed or not before continuing. This can be very time-consuming if we repeat this process several times.
With the makefile, we can separate all these steps into simple tasks, called targets, and chain them together. So in the end we can build and distribute our app by calling make build_mobile_stg.
Why use Makefile?
When used properly, the Makefile can give us flexibility and speed. The only limit is our creativity. We could use it to:
- To Automate the build and upload to Testflight and Firebase App Distribution using Fastlane, with precedence targets for testing and linting;
- Automate the generation of new files with build_runner
- Automate the committed code by formatting it and running tests each time before we push to git
- Using flavor or dart-define to inject new configurations to different builds and runs of the app, be it dev, staging, and prod or different branding.
What is also good about it is that we can make it universal. It means that we could take it from project to project and have it as our major toolset for app development. One thing to note is that it is very important that we use Tabs instead of spaces inside each target. This is especially true when copying and pasting content from the web. If we add spaces instead of tabs the following error message will be displayed:
Makefile:34 *** missing separator. Stop.
Conclusion:
Thanks for being with us on a Flutter Journey!
So, in this article, we have seen how to automate Flutter workflow with Makefile. Also, feel free to comment and provide any other suggestions regarding Flutter.
Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. Also, the portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
Flutter Agency is one of the most popular online portals dedicated to Flutter Technology. Daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.
Contemporary ventures
Recent blog
ready to get started?
Fill out the form below and we will be in touch soon!
"*" indicates required fields