Want some programming help? [close]

How to Publish Android Apps to Google Play Store

Introduction

Building Android apps can be really easy to get started with. There is a bit of a hurdle when it comes to jumping from the debug build to a release build because it requires keystores and private keys and app signing. It can be confusing. This guide will walk through all the steps needed to build a release APK that is fit for distribution and can be uploaded to the Google Play Store.

With the knowledge in this guide, you will be able to build signed release APKs that can be distributed and uploaded to the Google Play Store.

This guide assumes you already have an Android app or know how to create one, but only using debug builds. This guide will walk through the process of creating the keystore and signing APKs with self-signed certificates for distribution on the Google Play Store.

If you don't know hot to build Android apps, check out my Android related tutorials and streams:

You can also read up on the official Android Developer Documentation and Android Distribution Guide.

App signing

You can read up on app signing with the Android App Signing documentation

The main thing you need to know is that you will need a private key in order to sign your application. Signing your app is a requirement before publishing to the Google Play Store. You don't have to sign an app built in debug mode but you do in release mode.

Generate a self-signed certificate

To create your own private key, you can use the Java keytool. keytool comes with Java and is in the bin/ directory of the Java installation. If you need some tips on installing Java and dealing with multiple versions in Windows check out my tutorial Install multiple JDK in Windows for Java Development.

To learn about keytool and how to create and manage keys and certificates, check out my Java Keytool Tutorial.

# Generate an RSA key
keytool -genkey -v -keystore my-release-keys.keystore -alias MyApp -keyalg RSA -keysize 2048 -validity 10000

You will be prompted to fill out your name, location, and other data. Once it's created, you need to take care of the keystore file and store it in a safe and secure location. Keep it private and don't share it. Also DO NOT lose the keystore or forget the passwords. You will need the same key in order to publish app updates.

The important details to know are:

  • Where the keystore file is located
  • What the alias for your app is (the -alias option in the genkey command)
  • The passphrases used to secure the keys. You can choose to use the same passphrase for the keystore and the key itself or use a different passphrase for each.

For example, when using NativeScript Sidekick to publish Android apps to Google Play, you will need to provide the keystore file, the passphrase for the keystore, the alias name for the app key, and the password for the key.

Use your keystore to build a release APK

Once you have the keystore with your key in it, you can use it to sign APKs and create release builds.

With Android Studio

If you are using Android Studio, then go to Build -> Generate Signed Bundle or APK. It will ask you for:

  • Keystore path
  • Keystore password
  • Key alias
  • Key password

With NativeScript

Similarly, with NativeScript, you can build a release APK from the command-line or with NativeScript Sidekick.

To learn more about NativeScript, check out my NativeScript Tutorial.

tns build android --release \
  --key-store-path "$HOME/.keystore" \
  --key-store-password "Scr3t!" \
  --key-store-alias MyApp \
  --key-store-alias-password "Secr3t"

You can also configure NativeScript Sidekick to use your keystore to build release versions. Just point it to your keystore file and provide the passwords in the build menu.

Refer to the official NativeScript guide on Publishing to Google Play.

With Kivy

You can make Android apps with Python using Kivy. For a more detailed tutorial, check out my Python Kivy Tutorial.

You can build a release APK using buildozer and running the android release command. The important step before running the build command is to set the Python4Android environment variables that tell it which keystore and key to use.

export P4A_RELEASE_KEYSTORE=$HOME/.keystore
export P4A_RELEASE_KEYSTORE_PASSWD=s3cr3t
export P4A_RELEASE_KEYALIAS_PASSWD=s3cr3t
export P4A_RELEASE_KEYALIAS=mykey

python3 -m buildozer -v android release

Install and test your release APK

Be sure to thoroughly test your release version. You can use adb to install the APK to your device.

# Install (reinstall if necessary) an APK to device

adb install -r MyApp.apk

You can also just copy the file over to the device or use a web browser on the device to download a file over an HTTP web server. Check out my One-line HTTP Servers Tutorial for several examples of how to quickly spin up HTTP servers.

Publish on Google Play Store

Once you have your signed release APK you can distribute it and publish it to the Google Play Store. You will need to do a few things. Each one of these has a checkmark icon next to the menu item in the left letting you know whether you have completed the required task or not.

  • Created the application project
  • Create a release under App releases
  • Ensure Store listing has all the images it needs.
  • Fill out the Content rating section
  • Fill out the App content section
  • Fill out the Pricing & distribution section.

Log in to Google Play Console

Log in to the Google Play Console to view all your apps. If you don't already have an account, you need to create one and pay a one-time fee of around $25.

Create the app in Google Play Console

Go to https://play.google.com/apps/publish and go to your Applications. Click Create Application or Publish an Android App on Google Play.

Add the title of the app and click Create.

You will then need to upload some icon images, screenshots, promo images, and all the steps listed before:

  • Create a release under App releases
  • Ensure Store listing has all the images it needs.
  • Fill out the Content rating section
  • Fill out the App content section
  • Fill out the Pricing & distribution section.

Publish manually

  • In the Google Play Console, go to App releases.
  • Click in to the track you want to use (e.g. Beta)
  • Click Create Release
  • Fill out all the details and upload the APK
  • Click Save

Publish using a tool

You can use tools like NativeScript Sidekick to publish apps on your behalf. To do this, you need a service account with appropriate permissions and then you need to obtain an API for that service account user.

Get your service account API key

If you're using something like the NativeScript Sidekick or other tool to publish and configure your apps on your behalf, you need to get an service account JSON key. This API key allows 3rd party build tools like NativeScript Sidekick or Jenkins to publish your app. You don't have to use the service account

The process is something like this:

  • Create a service account in the IAM manager with the role of Project Owner.
  • Create the JSON key for the user
  • Grant the service account access in the specific app in the Google Play Console

To start, go to Google Play Console and then go to Settings -> API Access -> Create Service Account. This will send you to the Service accounts page in the IAM management.

On the IAM Service Accounts page click Create Service Account. Provide a name and description. Give the service account the role of Project -> Owner. When it is created, you will see an option to Create Key. Choose Create Key, and then pick JSON. It will save the key to your computer. This is the only place it will exist from here on out. You will have to create another one if you lose it, but its easy to replace. It is not as critical as retaining your keystore.

You will need to do one last step, and go back to the developer console Developer account -> User & permissions, and click Grant Access to finalize the access.

Once you have the JSON key file, you can use it in your applications like NativeScript Sidekick.

Push updates

To release a new version, go to the App releases page in the Google Play Console and create a new release.

Conclusion

After reading this guide, you should feel comfortable with the following topics:

  • How to create keystores and manage keys
  • How to build a signed release APK
  • How to create your application in the Google Play Console
  • How to publish your signed APK to the Google Play Store via the web interface or using 3rd party tools like NativeScript Sidekick

References

Advertisement