In this challenge, you will use Codemagic to handle all your app builds, tests, and releases automatically.

Goal

The goals of this challenge include:

  • Learn to prepare an app for release

  • Learn to build, test, sign, and publish an app using Codemagic

Challenges

Challenge 1: Prepare the app for release

  1. Host your Flutter app in your favorite Git provider, for example, GitHub.

  2. Include some tests in your Flutter application.

  3. Add an app launcher icon. A new Flutter app comes with a default launcher icon—you can use the default or customize your own. Follow the guide on the official Flutter documentation to customize your launcher icon.

  4. Add the final name of your application. For more information on naming your app, follow the guide in the official Flutter documentation.

  5. Assign your app a unique ID.

Challenge 2: Set up Codemagic

To use the CI/CD tool, you need a Codemagic account. If you do not have one, you can sign up for Codemagic with your Git provider. 

To set up Codemagic, you need to:

  1. Create an application and connect a repository from your Git provider.

  2. Select your project repository and type. In this case, the project type is Flutter App(via WorkFlow Editor).

Once your app is ready, you can add settings to control how it is built, tested, and deployed using the Workflow editor.

Challenge 3: Build your app with Codemagic

To build your app, you need to customize the build settings to suit your it:

  1. Click “Finish build setup” for first-time applications. For an existing app, click the settings icon.

  2. Select “Android” as your build platform on the Workflow editor page.

  3. Expand the “Build triggers” section and select your preferred build trigger. You can also configure the watched branches and tags. These settings will trigger an app build whenever they occur.

  4. Expand the “Build” section and select your app’s build format and mode. Since you will publish your app to the Google Play Store, select the “AAB” build format and “Release” mode.

  5. Save the changes and start a new build. If your app builds successfully, Codemagic will add a green check beside its name. Downloadable Android artifacts are also added.

Challenge 4: Test the app with Codemagic

To test your app, you need to customize the test settings:

  1. Go back to the Workflow editor page by clicking on the settings icon next to your app name. 

  2. Expand the “Tests” section. If you would like your build to stop if a test fails, check “Stop build if tests or analysis fail.” 

  3. Expand the “Integration and unit tests” section and enable Flutter tests. If your app has integration tests, you can configure the driver test settings accordingly.

  4. Save the changes and start a new build. If your tests run successfully, you will get a green check beside your app name. Expanding the “Testing” section on the build log shows the passed or failed tests.

Challenge 5: Sign your app

To publish on Google Play Store, you need to give your app a digital signature. You can add code signing to your app via the Flutter Workflow editor using the following steps:

  1. Create an upload keystore by running the command below in your Windows terminal and completing the prompts:

keytool -genkey -v -keystore c:\Users\USER_NAME\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

Replace USER_NAME with your user name. This command creates a Keystore file and stores it in your home directory.

If you are on Mac/Linux, run the command described in the official Flutter documentation.

  1. Configure signing in gradle, as described in the official Flutter documentation.

  2. Go back to the Workflow editor page, expand the “Android code signing” section under “Distribution,” and enable code signing.

  3. Upload the keystore file you generated in step one to the “Keystore” section. Add the upload as the key alias; this is the alias you added to the command in step 1 (…-alias upload).

  4. Save your changes and start a new build. You will use the artifacts generated to publish your first app. 

Challenge 6: Manually publish your app to Google Play Store

You need to have a developer account to publish your app to Google Play.

Once your account is ready, you’re set to create your first app. You need to add the app bundle manually and publish it to Google Play for the first app build. For subsequent builds, you can automate this via Codemagic; this is so because the automation will require an existing app ID on your Google Play account.

In your Google Play Console dashboard, upload the app bundle generated under code signing on the Google Play “App Bundle” section.

Roll out the created app release after creating and setting up your app for publishing. If your release was successful, you should have a release summary, as shown in the slides below.

Note the app version: 1(1.0.0).

Create an “Internal testing” release version of the app. This track is for internal testing and QA. If you wish to release your app to production, create your release under “Production.” A successful roll-out will display a similar summary under “Production.”

Challenge 7: Automatically publish your app to Google Play Store with Codemagic

You’ll need to update your app and release another version to your users at some point. This process can now be automated via the Workflow editor using the steps below:

  1. Get API Access to enable automated publishing. Follow the guide on the official Codemagic documentation to get a Google Play developer publishing API. The steps involve creating a service account on the Google Cloud Platform, where you will obtain a private key. When giving app permissions, be sure to select the app we published manually.

  2. Go back to the Workflow editor, expand the “Google Play” section under “Distribution,” and enable Google Play publishing. Upload the private key JSON file obtained in the first step under credentials. 

  3. Select the track chosen; this should match the track on Google Play. Select “Internal” and check the release as a draft if you went with “Internal testing.” If you went with “Production,” select the track only. 

  4. Save the changes.

If you start a new build at this point, your build will throw an APK specifying a version code that has already been used in error. 

To publish a new app version, you need to change the app build number to a higher number in your app code. You can do this by editing your app and pushing the changes or by using the Workflow environment variables

To test your push build trigger, you will update the app’s build number on your app code and push the changes to your repository. The push will trigger a new build. 

Since you added publishing to your workflow, Codemagic will do an automated publish for you. Codemagic would add a green check next to your app name if the build and deployment were successful. 

If you check your account on Google Play, you should see a new release of your app: 2(1.0.2).

Get hands-on with 1400+ tech skills courses.