Chapters

Hide chapters

Flutter Apprentice

Fourth Edition · Flutter 3.16.9 · Dart 3.2.6 · Android Studio 2023.1.1

Section II: Everything’s a Widget

Section 2: 5 chapters
Show chapters Hide chapters

Section IV: Networking, Persistence & State

Section 4: 6 chapters
Show chapters Hide chapters

20. Build & Release an Android App
Written by Stef Patterson

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

So you’ve finished building your app and you’re ready to let the world try it out. In this chapter, you’ll learn how to prepare your app for distribution through the Google Play Store, then release it for internal testing. In the next chapter, you’ll do the same for Apple’s App Store.

The steps you’ll follow to launch your app are straightforward:

  1. Create a signed release build.
  2. Prepare the Play Store for upload.
  3. Upload the build.
  4. Notify testers that the build is ready.

To complete this chapter, you’ll need a Google Play developer account. If you want to test the download of the release from the Google Play store you’ll also need a physical Android device.

Set Up for Release

Before you can upload a build for distribution, you need to build it with a release configuration. When you create a new Flutter project, you automatically create a debug build configuration. This is helpful while in development, but it’s not suitable for distribution in the store for several reasons:

  • App bloat: A debug build is extra large because of the symbols and overhead needed for hot reload/restart and for source debugging.
  • Resource keys: It’s typical to point your debug app at a sandbox environment for services and analytics so you don’t pollute production data or violate user privacy.
  • Unsigned: Debug builds aren’t signed yet. To upload to the store, you need to sign the app to verify you are the one who built it.
  • Google says so: The Play Store won’t allow you to upload a debug build.

The app’s configuration spreads across several files. In the next steps, you’ll see how to modify some key pieces of your app to prepare your build for submission to the Play Store.

If you’re following along with your app from the previous chapter, open it and keep using it with this chapter. If not, just locate the projects folder for this chapter, open the starter project in Android Studio and remember to get dependencies.

Note: If you use the starter app or didn’t add it in the last chapter, add your apiKey in lib/network/spoonacular_service.dart because your app needs to run completely to submit it to the store.

Preparing the Manifest

Debug builds have broad permissions, but apps released for distribution need to declare which aspects of the user’s hardware or systems they need to access. The Android Manifest file is where you declare permissions.

<uses-permission android:name="android.permission.INTERNET" />

Updating build.gradle

build.gradle is where you describe different build configurations. You’ll change it next. When you set up the app, you used the default debug configuration. Now, you’ll add a release configuration to produce a bundle you can upload to the Play Store.

applicationId "com.kodeco.recipe_finder"

Creating a Signing Key

Before you can distribute the app, you need to sign it. This ensures that all future versions come from the same developer.

keytool -genkey -v -keystore recipes.jks -keyalg RSA -keysize 2048 -validity 10000 -alias recipes
keytool -genkey -v -keystore %userprofile%\upload-keystore.jks ^
        -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 ^
        -alias upload

**/android/key.properties
./recipes.jks

Accessing The Signing Key

Now that you’ve created a key, you need to supply the build system with the information necessary to access it. To do that, you’ll create a separate file to store the password information.

storePassword={YOUR PASSWORD}
keyPassword={YOUR PASSWORD}
keyAlias=recipes
storeFile=../../recipes.jks

Referencing The Signing Key

You now have a key and its password, but signing doesn’t happen automatically. During the build, you need to open the keystore and sign the app bundle. To do this, you need to modify the build… and when you think about modifying the build process, you should think about build.gradle.

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
signingConfigs {
   release {
       keyAlias keystoreProperties['keyAlias']
       keyPassword keystoreProperties['keyPassword']
       storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
       storePassword keystoreProperties['storePassword']
   }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

Build an App Bundle

With build.gradle in place, you can leave the final steps to create a signed Android App Bundle up to the Flutter build system. The bundle will contain everything you need to upload your app to the Play Store.

flutter build appbundle

AAB Versus APK

If you’ve been working with Android for a while, you might be expecting to create an APK file. When you do a debug build from Android Studio, you get an APK file.

flutter build apk --split-per-abi

Uploading to The Google Play Store

Your next step to getting your app out in the wide world is to upload it to the Google Play Store. You’ll need a Google Play Developer account to do that.

Creating a New App

Once you’re in the Play Console, the next step is to create an app. This gives you a place to upload your build. The big Create app button will do the trick — click it to get started. The location of the button depends on whether this is your first app.

Providing Assets and a Description

Your next step before publishing is to upload app assets, such as icons and screenshots, and provide a description for the app. You’ll do this in the Main store listing tab.

This is an app to find recipes on the web.
With Recipe Finder, the world’s premier recipe search app, you’ll find all sorts of interesting things to cook. Bookmark your favorite ones to put together a shopping list.

Entering The Rest of The Information

However, you still haven’t added enough information for the Play Store to allow you to distribute your app. Because you can promote an uploaded build for sale in the store, the Play Console wants you to fill out a lot of information first.

Set Privacy Policy

For privacy policy you must include a link to where you are hosting your app’s privacy policy. This is mandatory for apps targeting children under 13. But it’s a good idea for all apps, as customers expect it these days.

App Access

For App access, select that all functionality is available since there are no restrictions.

Ads

For Ads, indicate that the app doesn’t contain ads.

Content Rating

To receive a content rating, you’ll have to answer a questionnaire. Click Start questionnaire.

Target Audience

This app is not for children, so simply select 18 and up. That way, there’s no problem if a user looks up a saucy dish, like a bolognese.

News

This is not a news app, so select No.

COVID-19 Contact Tracing and Status Apps

This is not a COVID-19 contact tracing or status app.

Data Safety

The data safety questionnaire needs information about how the app collects user data. Fortunately, this app does not collect any data, so your answers will be simple and easy.

App Category

Return to the Dashboard and click Select an app category and provide contact details.

App Pricing and Merchant Info

If your Google Play Store account is new and you haven’t set up your financial information yet, you need to tell Google where to send money. In this case, though, it’s not a big deal because this is a free app.

Uploading a Build

The next step in your app’s journey is to upload a build for testing. The Play Store provides different levels of testing:

<en-US>
This release is just to demonstrate uploading and sending out a build.
</en-US>

Distribution

On the next screen, if there are any errors listed under Errors, warnings and messages, you’ll have to resolve them before you can proceed. It’s OK to roll out with warnings, such as a lack of debug symbols.

Installing The App

Using the web browser on your Android device, navigate to that link and you’ll see the invitation to join the test.

Key Points

  • Release builds need a signed release configuration.
  • To upload to the Google Play Store, you’ll need to list all necessary permissions.
  • To test an app, go to the Google Play Console, create the app with store metadata, create a release, upload the build and invite testers.

Where to Go From Here?

For the most part, you don’t need the Flutter tools to prepare the app bundle for release. It’s all Android-specific work. To learn more about how Android Studio can help prepare and sign release builds and how to use the Google Play Console, check out our Android Apprentice book: https://www.kodeco.com/books/android-apprentice. This covers the Google Play Console more in-depth.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2024 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now