Skip to main content

How to generate a new private key and submit it to Google Play for signing your Android app, you can follow these steps:

Generate a New Keystore (Private Key)

You can generate a new keystore file (which includes the private key) using the keytool utility that comes with the Java Development Kit (JDK). Open a command prompt or terminal and run the following command to generate a new keystore:

keytool -genkeypair -v -keystore your-keystore-name.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias your-alias-name

Here's what each option means:
-genkeypair: Generates a key pair (a public key and a private key).
-v: Enables verbose output to see the process.
-keystore your-keystore-name.keystore: Specifies the name of the keystore file you want to create. You can choose any name you like but use the ".keystore" extension.
-keyalg RSA: Specifies the key algorithm (you can use RSA for modern apps).
-keysize 2048: Sets the key size to 2048 bits (adjust as needed).
-validity 10000: Sets the validity period of the key pair in days (adjust as needed).
-alias your-alias-name: Specifies an alias for the key pair. This is used to identify the key within the keystore.

Replace 'your-keystore-name.keystore' with the desired name of your keystore file.

Change -alias your-alias-name to specify an alias for your key (you can choose any alias name).

 

Follow the Prompts:

When you run the command, you'll be prompted to enter information such as your name, organization, and a password for the keystore. Make sure to remember the password; you'll need it later.

 

Save the Keystore File

After providing the required information, the keystore file will be generated in the current directory. Make sure to keep this file in a secure location, as it's used to sign your app for submission to the Google Play Store.

Once you have generated the keystore, you can use it to sign your Android app's APK before uploading it to the Google Play Developer Console. During the app submission process, you'll be prompted to upload the keystore file and provide the keystore password. Keep your keystore and password safe and make backups to prevent data loss.

During the process, you'll be prompted to enter a keystore password and provide information about your organization.

 

Securely Store the Keystore:

Ensure that you securely store the keystore file and its password. Losing access to the keystore or its password can result in the inability to update or publish your app.

 

Configure Gradle Signing in Your Android Project

Open your Android project in Android Studio and configure the signing settings in your app's "build.gradle" file. Update the signingConfigs and buildTypes sections as follows

android {
   ...
   signingConfigs {
       release {
           storeFile file('path/to/your/keystore/my-release-key.keystore')
           storePassword 'your_keystore_password'
           keyAlias 'my-key-alias'
           keyPassword 'your_key_password'
       }
       // You can define additional signing configurations as needed
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
           ...
       }
       // You can define additional build types as needed
   }
   ...
}

Replace 'path/to/your/keystore/my-release-key.keystore' with the actual path to your keystore file.

Replace 'your_keystore_password' and 'your_key_password' with your keystore password and key password, respectively.

 

Build a Release Version of Your App:

Build a release version of your app by selecting "Build" > "Build Bundle(s) / APK(s)" > "Build APK(s)" from the Android Studio menu.

 

Sign and Align the APK:

After building the release APK, Android Studio will sign and align it automatically using the keystore and passwords you provided in the Gradle configuration.

 

Submit to Google Play Console:

Log in to your Google Play Console account.

Create a new release for your app, or edit an existing one.

Under the "App bundles and APKs" section, click "Upload APK" or "Add from Library" to upload the signed release APK.

Follow the steps to complete the submission process, including providing release notes and targeting specific devices or regions.

 

KeyStore check content of file

If you want to list the contents of your keystore file (and alias name), the run

keytool -v -list -keystore /path/to/keystore

However, if you are looking for a specific alias, you can also specify it in the command:

keytool -list -keystore /path/to/keystore -alias {your-alias}

When running either of these commands, your will be prompted for the keystore's password

Enter keystore password:

Response post entering the correct password

 

 

Related articles

Andrew Fletcher31 Oct 2023
Android icon not changing
If the Android app icon is not changing from the default icon (in my situation this was the Capacitor icon), here are some steps to troubleshoot and resolve the issue: Check the Icon FilesEnsure that you have provided the correct icon files in the appropriate directory. In a Capacitor project,...