Chapters

Hide chapters

Flutter Apprentice

Second Edition · Flutter 2.5.1 · Dart 2.14.2 · Android Studio 2020.3.1

Section IV: Networking, Persistence and State

Section 4: 7 chapters
Show chapters Hide chapters

Appendices

Section 7: 2 chapters
Show chapters Hide chapters

17. Build & Release an Android App
Written by Michael Katz

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 deployment 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 and 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 store submission 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 debuggable app.

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.

If you’re following along with your app from the previous chapters, 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, don’t forget to add your apiKey and apiId in network/recipe_service.dart.

Preparing the manifest

Debug builds get broad permissions, but apps released through reputable stores 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.raywenderlich.recipe_finder"
targetSdkVersion 29

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

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))
}
compileSdkVersion 29
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.

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 and content

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.

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 let Google know 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.raywenderlich.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