Create Upload key and app’s release bundle (.aab) file

Part II — Publish app manually to Play store | Story 2— Create Upload key and app’s release bundle (.aab) file

--

In the previous post of this Part II of the series, we registered the app in Google Play developer console.

Next step, before we create a release of the app on Google Play console, is to generate an Upload key and then create a release bundle (.aab) file of our React-Native project’s android app.

To release our App to Google Play store, we need to generate an executable binary file of our compiled app code in the form that Google Play store accepts which could be either in the form of a .apk file or a .aab file.

Android Package (APK) (wiki) is the package file format used by the Android operating system for distribution and installation of mobile apps.

Android App Bundle(AAB) is a new upload format that includes all your app’s compiled code and resources, but defers APK generation and signing to Google Play using Google’s app serving model called Dynamic Delivery.

Signed vs Unsigned APK

When we build our app’s APK/AAB, if it has a .bin file having an encrypted digital security private code (called AppSigning key), it becomes a digitally signed APK/AAB.
APK/AAB built without an AppSigning key would be an unsigned APK.

In order for an app to be installable on a user’s android device, the app’s APK/AAB must be a signed APK/AAB.

We can set our own AppSigning key; however Google Play developer console provides an option to create and manage/maintain/secure the key for us. This option has few advantages than creating/maintaining our own AppSigning key.
When we opt in to App signing by Google Play option, we need to provide the play store with our app’s .aab file and Google Play store would take care of generating APK and signing it with AppSigning key.

Ok, as we are going to use App signing by Google Play option for our app’s release, we don’t need to generate AppSigning key.

Next we need is Upload key.

Upload Key

Another key needed to push/upload the app’s release apk/aab file to Google Play Store is something called Upload key; we need to sign our app’s binary with an Upload key. i.e our app’s apk/aab should also be generated with an additional file having a digital code called Upload key. The file that would contain this upload key will have an extension .keystore.

To generate this Upload key, Android studio provides a form in its IDE to generate and configure the Upload key for us. Alternatively it can also be generated from the command line/terminal window.

Generating Upload key/keystore

We would use the command line option to generate the upload key and keystore. As I am using mac for app development, the below instructions are for OSX. Instructions for Windows can be found here at the react-native docs.

For mac, first find your JDK bin folder using the below command:

$ /usr/libexec/java_home

It will output the path of your JDK folder. On the terminal, cd to your JDK bin folder.

Now, run the below command from our JDK Bin folder and follow the instructions answering the prompted questions.

sudo keytool -genkey -v -keystore rnTSgitlabCICDExample-upload.keystore -alias rnTSgitlabCICDExample-upload -keyalg RSA -keysize 2048 -validity 10000
(click over image to zoom)

- Once the command is complete, the upload keystore file should be created under your JDK Bin folder.
(Note: You must keep the keystore file secured. In case you’ve lost upload key or it’s been compromised you should follow these instructions.)

- Move the created keystore file rnTSgitlabCICDExample-upload.keystore under the android/app directory in your project folder.
- Edit the file ~/.gradle/gradle.properties or android/gradle.properties, and add the following (replace ***** with the correct keystore password, alias and key password that you used when generating the keystore/key above),

MYAPP_UPLOAD_STORE_FILE=rnTSgitlabCICDExample-upload.keystore
MYAPP_UPLOAD_KEY_ALIAS= rnTSgitlabCICDExample-upload
MYAPP_UPLOAD_STORE_PASSWORD=*****
MYAPP_UPLOAD_KEY_PASSWORD=*****

These are going to be global Gradle variables, which we would later use in our Gradle config to sign our app.

(click over image to zoom)

𝑵𝔬𝔱𝔢 𝔞𝔟𝔬𝔲𝔱 𝔰𝔢𝔠𝔲𝔯𝔦𝔱𝒚 : If you are concerned above about the upload keystore file being stored in the repository and its passwords in plaintext, we will later move these to the Gitlab CI/CD variables and use those variable instead of the direct values/file in build.gradle.

Let’s move on for now with our manual steps to bundle the app.
Next, edit the file android/app/build.gradle in your project folder, and add the signing config,

...
android {
...
defaultConfig { ... }
signingConfigs {
debug {
...
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}

}
buildTypes {
release {
...
signingConfig signingConfigs.release
...
}
}
}
...
(click over image to zoom)

Generating release bundle .𝚊𝚊𝚋 file

We are now ready to create our app’s android bundle. Run the following commands in the terminal from the project’s root folder:

$ cd android
$ ./gradlew bundleRelease

Gradle’s bundleRelease will bundle all the code files needed to run your app into the AAB (Android App Bundle).
The generated AAB can be found under android/app/build/outputs/bundle/release/app-release.aab, and is ready to be uploaded to Google Play 👇

📌 🅝🅞🅣🅔: App's .aab file created manually

Alright, now that we have our app’s release Android App Bundle (.aab) file created, next, we are ready to create/configure a release for our app on Google Play console, push this .aab file to the created release and publish the app.

Prev: Register app in GPC 🏠Next: Config release in GPC

--

--