Building a Flutter package
One of the important things to take into account is that all Flutter packages are rated depending on the quality of the package. This means that if you provide an
Example you will get more points. But don’t worry, whenever you publish your package you will be presented with some information on how to improve this score.
Composing the Travis-CI configuration file
All you have to do is create a new file called
.travis.yml in the root of your project and copy the content below:
Note that we’re only publishing our package whenever we create a new
Once you have your
.travis.yml file ready and set up, you must create a publication script.
Let’s create a new folder called
.travis and a file called
publish.sh in it. Copy the script below:
As you can see, the publication script is expecting some environment variables. But, how do we get them?
Unfortunately, the only way to get this information is by publishing your package manually so you can authenticate and get all the necessary tokens.
This should be an easy one-time process so let’s do that!
First, let’s test that everything is working fine and let’s do a “fake publication” by executing:
pub publish --dry-run
If you see something wrong, fix it. If everything is fine then just:
You will be immediately required to open your browser and authenticate with your Google credentials and once you authenticate, a new file will be available to you in your computer:
Open it and there you will find all the information you need to set up the Travis environment variables.
Things to take into account
There are a few things that I found out the hard way:
- If you provide an example folder make sure that you have a
pubspec.yamlin it because otherwise
flutter packages getcommand will fail. Make sure that everything works in this folder too before pushing any changes.
- Check that your
publish.shscript has execution permissions. If you don’t do this you will get a cryptic 127 error.
pub getis called automatically by
Traviswhen you select
Dartas the default language. This will lead you to receive an error (it seems to be a known issue in Travis). The only way to get rid of it is to completely override the
installstep. This is already managed for you in our previous
- The publication tokens will eventually expire so we’ll have to reset the
Travisenvironment variables when this happens (and hence do a manual publication again :( ).
Trying it out
If you have completed all the steps, you’re project will be analyzed, tested and built without publishing every time you
push to your git repository.
Whenever you’re ready to publish, just create and push a new tag and
Travis will take care of it!
Of course, feel free to customize the scripts according to your needs.
Originally published at robertohuertas.com on January 20, 2019.