Reader small image

You're reading from  Android Studio 3.5 Development Essentials - Kotlin Edition

Product typeBook
Published inMay 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781951442002
Edition1st Edition
Languages
Right arrow
Author (1)
Neil Smyth
Neil Smyth
author image
Neil Smyth

Neil Smyth has over 25 years of experience in the IT industry, including roles in software development and enterprise-level UNIX and Linux system administration. In addition to a bachelor's degree in information technology, he also holds A+, Security+, Network+, Project+, and Microsoft Certified Professional certifications and is a CIW Database Design Specialist. Neil is the co-founder and CEO of Payload Media, Inc. (a technical content publishing company), and the author of the Essentials range of programming and system administration books.
Read more about Neil Smyth

Right arrow

89. Creating, Testing and Uploading an Android App Bundle

Once the development work on an Android application is complete and it has been tested on a wide range of Android devices, the next step is to prepare the application for submission to Google Play. Before submission can take place, however, the application must be packaged for release and signed with a private key. This chapter will work through the steps involved in obtaining a private key, preparing the Android App Bundle for the project and uploading it to Google Play.

89.1 The Release Preparation Process

Up until this point in the book, we have been building application projects in a mode suitable for testing and debugging. Building an application package for release to customers via Google Play, on the other hand, requires that some additional steps be taken. The first requirement is that the application be compiled in release mode instead of debug mode. Secondly, the application must be signed with a private key that uniquely identifies you as the application’s developer. Finally, the application must be packaged into an Android App Bundle.

While each of these tasks can be performed outside of the Android Studio environment, the procedures can more easily be performed using the Android Studio build mechanism as outlined in the remainder of this chapter. First, however, it is important to understand a little more about Android App Bundles.

89.2 Android App Bundles

When a user installs an app from Google Play, the app is downloaded in the form of an APK file. This file contains everything needed to install and run the app on the user’s device. Prior to the introduction of Android Studio 3.2, the developer would generate one or more APK files using Android Studio and upload them to Google Play. In order to support multiple device types, screen sizes and locales this would require either the creation and upload of multiple APK files customized for each target device and locale, or the generation of a large universal APK containing all of the different configuration resources and platform binaries within a single package.

Creating multiple APK files involved a significant amount of work that had to be repeated each time the app needed to be updated imposing a considerable time overhead to the app release process.

The universal APK option, while less of a burden to the developer, caused an entirely unexpected...

89.3 Register for a Google Play Developer Console Account

The first step in the application submission process is to create a Google Play Developer Console account. To do so, navigate to https://play.google.com/apps/publish/signup/ and follow the instructions to complete the registration process. Note that there is a one-time $25 fee to register. Once an application goes on sale, Google will keep 30% of all revenues associated with the application.

Once the account has been created, the next step is to gather together information about the application. In order to bring your application to market, the following information will be required:

Title – The title of the application.

Short Description - Up to 80 words describing the application.

Full Description – Up to 4000 words describing the application.

Screenshots – Up to 8 screenshots of your application running (a minimum of two is required). Google recommends submitting...

89.4 Configuring the App in the Console

When the Create Application button is first clicked, the Store listing screen will appear as shown in Figure 89-1 below. The screen may also be accessed by selecting the Store listing option (marked A) in the navigation panel. Once all of the requirements have been met for the Store listing screen, both the Content rating (B) and Pricing & distribution (C) screens must also be completed:

Figure 89-1

Once the app entry has been fully configured, the next step is to enable app signing and upload the app bundle.

89.5 Enabling Google Play App Signing

Up until recently, Google Play uploads were signed with a release app signing key from within Android Studio and then uploaded to the Google Play console. While this option is still available, the recommended way to upload files is to now use a process referred to as Google Play App Signing. For a newly created app, this involves opting in to Google Play App Signing and then generating an upload key that is used to sign the app bundle file within Android Studio. When the app bundle file generated by Android Studio is uploaded, the Google Play console removes the upload key and then signs the file with an app signing key that is stored securely within the Google Play servers. For existing apps, some additional steps are required to enable Google Play Signing and will be covered at the end of this chapter.

Within the Google Play console, select the newly added app entry from the dashboard and click on the App releases option located in the left...

89.6 Creating a Keystore File

To create a keystore file, select the Android Studio Build -> Generate Signed Bundle / APK… menu option to display the Generate Signed Bundle or APK Wizard dialog as shown in Figure 89-4:

Figure 89-4

Verify that the Android App Bundle option is selected before clicking on the Next button.

In the event that you have an existing release keystore file, click on the Choose existing… button on the next screen and navigate to and select the file. If you have yet to create a keystore file, click on the Create new… button to display the New Key Store dialog (Figure 89-5). Click on the button to the right of the Key store path field and navigate to a suitable location on your file system, enter a name for the keystore file (for example, release.keystore.jks) and click on the OK button.

The New Key Store dialog is divided into two sections. The top section relates to the keystore file. In this section, enter a strong password...

89.7 Creating the Android App Bundle

The next step is to instruct Android Studio to build the application app bundle file in release mode and then sign it with the newly created private key. At this point the Generate Signed Bundle or APK dialog should still be displayed with the keystore path, passwords and key alias fields populated with information:

Figure 89-7

Make sure that the Export Encrypted Key option is enabled and, assuming that the other settings are correct, click on the Next button to proceed to the app bundle generation screen (Figure 89-8). Within this screen, review the Destination Folder: setting to verify that the location into which the app bundle file will be generated is acceptable. In the event that another location is preferred, click on the button to the right of the text field and navigate to the desired file system location.

Figure 89-8

Click on the Finish button and wait for the Gradle system to build the app bundle. Once the build is...

89.8 Generating Test APK Files

An optional step at this stage is to generate APK files from the app bundle and install and run them on devices or emulator sessions. Google provides a command-line tool called bundletool designed specifically for this purpose which can be downloaded from the following URL:

https://github.com/google/bundletool/releases

At time of writing, bundletool is provide as a .jar file which can be executed from the command line as follows (noting that the version number may have changed since this book was published):

java -jar bundletool-all-0.9.0.jar

Running the above command will list all of the options available within the tool. To generate the APK files from the app bundle, the build-apks option is used. To generate APK files that can be installed onto a device or emulator the files will also need to be signed. To achieve this include the --ks option specifying the path of the keystore file created earlier in the chapter, together with the --ks...

89.9 Uploading the App Bundle to the Google Play Developer Console

Return to the internal testing track screen within the Google Play Console and upload the app bundle by dragging and dropping it onto the designated area, or click on the button to browse for the bundle file:

Figure 89-10

After the app bundle file has uploaded, Google Play will generate all of the necessary APK files ready for testing. Once the APK files have been generated, scroll down to the bottom of the screen and click on the Save button. Once the settings have been saved, click on the Review button.

89.10 Exploring the App Bundle

On the review screen, click on the bundle name to unfold the information about the bundle as shown in Figure 89-11:

Figure 89-11

This section of the screen provides summary information relating to the API levels, screen layouts and platforms supported by the app bundle. For more information, click on the Explore App Bundle option highlighted in the figure above. This will display information about the size savings compared to a universal APK file (marked A in Figure 89-12) and provide the option to download individual APK files for local testing purposes (B) as an alternative to using the bundletool:

Figure 89-12

The bundle explorer also lists the supported screen densities (C) and respective install APK size. Clicking on a View Devices option for a screen density will display the devices that are supported by the APK file:

Figure 89-13

At this point, the app is ready for testing but cannot be rolled out until some testers...

89.11 Managing Testers

If the app is still in the Internal, Alpha or Beta testing phase, a list of authorized testers may be specified by selecting the app from within the Google Play console, clicking on App releases in the navigation panel, selecting the Manage button for the release type and unfolding the Manage testers section of the release screen as shown in Figure 89-14:

Figure 89-14

The following options are available for app testing:

Internal Testing – The app is made available to up to 100 designated internal testers. This is the fastest way to get the app to a small group of known testers.

Closed Testing – Testing is only available for designated users identified by email address or membership in Google Groups and Google+ communities.

Open Testing – The app is made available to all users within the Google Play Store. Users are provided with a mechanism to provide feedback to you during testing. The total number...

89.12 Uploading New App Bundle Revisions

The first app bundle file uploaded for your application will invariably have a version code of 1. If an attempt is made to upload another bundle file with the same version code number, the console will reject the file with the following error:

You need to use a different version code for your APK because you already have

one with version code 1.

To resolve this problem, the version code embedded into the bundle file needs to be increased. This is performed in the module level build.gradle file of the project, shown highlighted in Figure 89-15:

Figure 89-15

By default, this file will typically read as follows:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 28

    defaultConfig {

        applicationId "com.example.myapplication"

        minSdkVersion...

89.13 Analyzing the App Bundle File

Android Studio provides the ability to analyze the content of an app bundle file. To analyze a bundle file, select the Android Studio Build -> Analyze APK… menu option and navigate to and choose the bundle file to be reviewed. Once loaded into the tool, information will be displayed about the raw and download size of the package together with a listing of the file structure of the package as illustrated in Figure 89-16:

Figure 89-16

Selecting the classes.dex file will display the class structure of the file in the lower panel. Within this panel, details of the individual classes may be explored down to the level of the methods within a class:

Figure 89-17

Similarly, selecting a resource or image file within the file list will display the file content within the lower panel. The size differences between two bundle files may be reviewed by clicking on the Compare with previous APK… button and selecting a second...

89.14 Enabling Google Play Signing for an Existing App

To enable Google Play Signing for an app already registered within the Google Play console, begin by selecting that app from the list of apps in the console dashboard. Once selected, click on the App signing link in the left-hand navigation panel as shown in Figure 89-18:

Figure 89-18

The first step is to click on the button to download the PEPK Tool (A) which will be used to encrypt the app signing key for the project. Once downloaded, copy it to the directory containing your existing keystore file and run the following command where (<your app signing key file> and <your alias> are replaced by the name of your keystore file and the corresponding alias key respectively):

java -jar pepk.jar --keystore=<your app signing key file> --alias=<your alias> --output=encrypted_private_key_path --encryptionkey=<your app signing key>

Enter the keystore and key passwords when prompted, then check...

89.15 Summary

Once an app project is either complete, or ready for user testing, it can be uploaded to the Google Play console and published for production, internal, alpha or beta testing. Before the app can be uploaded, an app entry must be created within the console including information about the app together with screenshots to be used within the Play Store. A release Android App Bundle file is then generated and signed with an upload key from within Android Studio. After the bundle file has been uploaded, Google Play removes the upload key and replaces it with the securely stored app signing key and the app is ready to be published.

The content of a bundle file can be reviewed at any time by loading it into the Android Studio APK Analyzer tool.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Android Studio 3.5 Development Essentials - Kotlin Edition
Published in: May 2019Publisher: PacktISBN-13: 9781951442002
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime

Author (1)

author image
Neil Smyth

Neil Smyth has over 25 years of experience in the IT industry, including roles in software development and enterprise-level UNIX and Linux system administration. In addition to a bachelor's degree in information technology, he also holds A+, Security+, Network+, Project+, and Microsoft Certified Professional certifications and is a CIW Database Design Specialist. Neil is the co-founder and CEO of Payload Media, Inc. (a technical content publishing company), and the author of the Essentials range of programming and system administration books.
Read more about Neil Smyth