Reader small image

You're reading from  Android Studio 4.1 Development Essentials – Java Edition

Product typeBook
Published inMay 2021
PublisherPackt
ISBN-139781801815161
Edition1st Edition
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

84. 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.

84.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.

84.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...

84.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...

84.4 Configuring the App in the Console

When the Create app button is first clicked, the app details and declarations screen will appear as shown in Figure 84-1 below:

Figure 84-1

Once the app entry has been fully configured, click on the Create app button (highlighted in the above figure) to add the app and display the dashboards screen. Within the dashboard, locate the Initial setup section and unfold the list of steps to configure the app store listing:

Figure 84-2

Work through the list of links and provide the requested information for your app, making sure to save the changes at each step.

84.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 All Apps screen (accessed via the option located at the top of the...

84.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 84-4:

Figure 84-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 84-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...

84.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 84-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 84-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 84-8

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

84.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...

84.9 Uploading the App Bundle to the Google Play Developer Console

Return to the Google Play Console and select the Internal testing option (marked A in Figure 84-10) located in the Testing section of the navigation panel before clicking on the Create new release button (B):

Figure 84-10

On the resulting screen, click on the Continue button (marked A below) to confirm the use of Google Play app signing, then drag and drop the bundle file generated by Android Studio onto the upload drop point (B):

Figure 84-11

When the upload is complete, scroll down the screen and enter the release name and optional release notes. The release name can be any information you need to help you recognize the release and it is not visible to users.

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...

84.10 Exploring the App Bundle

On the review screen, click on the arrow to the right of the upload bundle as indicated in Figure 84-12:

Figure 84-12

In the resulting panel, click on the Explore bundle link to load the app bundle explorer. This provides summary information relating to the API levels, screen layouts and platforms supported by the app bundle:

Figure 84-13

Clicking on the Go to device catalog link will display the devices that are supported by the APK file:

Figure 84-14

At this point, the app is ready for testing but cannot be rolled out until some testers have been set up within the console.

84.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 Internal testing in the navigation panel, and selecting the Testers tab as shown in Figure 84-15:

Figure 84-15

To add testers, click on the Create email list button, name the list and specify the email addresses for the test users either manually or by uploading a CSV file.

The “Join on the web” URL may now be copied from the screen and provided to the test users so that they accept the testing invitation and download the app.

84.12 Rolling the App Out for Testing

Now that an internal release has been created and a list of testers added, the app is ready to be rolled out for testing. Remaining within the Internal testing screen, select the Releases tab before clicking on the Edit button for the recently created release:

Figure 84-16

On the review screen, scroll to the bottom and click on the Start rollout to Internal testing button. After a short delay while the release is processed, the app will be ready to be downloaded and tested by the designated users.

84.13 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 84-17:

Figure 84-17

By default, this file will typically read as follows:

plugins {

    id 'com.android.application'

}'

 

android {

    compileSdkVersion 29

    buildToolsVersion "30.0.0"

    defaultConfig {

        applicationId...

84.14 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 84-18:

Figure 84-18

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 84-19

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...

84.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 4.1 Development Essentials – Java Edition
Published in: May 2021Publisher: PacktISBN-13: 9781801815161
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 £13.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