Building a snap package
How to build and release a snap package with codemagic.yaml
Setting up snap packaging
Optionally, run the
snapcraft snap command locally to ensure that everything is set up.
You should store the
snapcraft.yaml file in the repository root. Another option is to store
snapcraft.yaml in the
.snap folder that is located in repository root.
codemagic.yamlconfiguration file that builds and releases a snap package in GitHub.
Building snap packages
snapcraft snap command in the
scripts section of your
codemagic.yaml file as in the example below. The output of this command is a
.snap artifact. It can later be used for publishing to the Snapcraft Snap Store.
workflows: snap-build: name: Snapcraft Build instance_type: linux environment: SNAPCRAFT_BUILD_ENVIRONMENT: host scripts: - name: Create a snap script: snapcraft snap --output flutter-codemagic-example.snap artifacts: - '**/*.snap'
Additionally, you may want to install the generated
.snap package onto your machine for testing. The package will not be code signed unless you publish it to Snapcraft, so you would need to use the
--dangerous flag to install the package without code signing:
snap install your-package.snap --dangerous
In case you are packaging a Flutter application, be sure to set
SNAPCRAFT_BUILD_ENVIRONMENT environment variable to
host. It is required to avoid virtualization. Read more about virtualization options here. Additionally, Snapcraft manages all the dependencies according to
snapcraft.yaml configuration. There is no need to include Flutter version in
instance_type: linux_x2in your
codemagic.yaml. See the build machine specification here.
Publishing snap packages
Snap packages can be published to the Snapcraft Snap Store.
- Generate your Snapcraft credentials file by running the following command locally.
snapcraft export-login snapcraft-login-credentials
You will be asked to enter your Snapcraft account username and password.
- Drag and drop the credentials file to the encryption interface in Codemagic. This is available via the lock icon next to the yaml editor in your app settings. Read more about encrypting sensitive info in Codemagic here.
- Add the encrypted value to
codemagic.yamlas an environment variable with the name
- In the
scriptssection, add steps to log in to Snapcraft via CLI, build the snap package and release it to the desired channel.
scripts: - name: Authenticate script: | echo $SNAPCRAFT_LOGIN_CREDENTIALS | base64 --decode > /home/builder/snapcraft-login-credentials snapcraft login --with /home/builder/snapcraft-login-credentials - name: Create a snap script: snapcraft snap --output flutter-codemagic-example.snap - name: Upload and release script: snapcraft upload flutter-codemagic-example.snap --release stable