Building a Release APK and AAB file for Your React Native Android Project

Building APK , Signing Key , Changing app name , changing app icons , changing version of app etc. all the things are covered with best solution .

ยท

3 min read

Prerequisites :

  • Java Development Kit (JDK): React Native relies on the JDK. Make sure you have it installed and configured in your development environment.

  • Android Studio (Recommended): While not strictly required, Android Studio is helpful for managing settings, viewing the build process output, and potentially troubleshooting. Especially useful in case you want to change icons , rounded icons which are required are best managed from android studio .

    • Step By Step Guide :

      Here's a systematic breakdown of generating a signed release APK for your React Native Android project, incorporating the best aspects of clarity and organization:

      1. Generate an Upload Key

        • Open a terminal window as administrator. Navigate to the JDK's "bin" directory (usually located at C:\Program Files\Java\jdkx.x.x_x\bin).
          or
          Open VS code as administrator.
          Navigate to your project folder in vscode and than navigate to android by doing cd android.

        • Execute the keytool command:

          Bash, powershell ( any other of your choice)

            keytool -genkeypair -v -storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
          
        • You can rename your keystore and alias - my-upload-key.keystore (app-renamed-key.keystore), my-key-alias(app-renamed-alias) .

        • Securely store your keystore: It's critical to keep this file safe and backed up. Losing it means you won't be able to issue updates to your app on the Google Play Store.

      2. Set up Gradle Variables:

        • Place themy-upload-key.keystore file under the android/app directory in your project folder.

        • Create or edit thegradle.properties file: You'll either find it in ~/.gradle/gradle.properties (user-level) or in your project's android/gradle.properties (project-level).

        • Add the following lines (replace values with your actual details):

            MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
            MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
            MYAPP_UPLOAD_STORE_PASSWORD=*****
            MYAPP_UPLOAD_KEY_PASSWORD=*****
          

          In password you need to enter the password you entered at the time you generate the keystore key.

      3. Add Signing Config tobuild.gradle

        • Open:android/app/build.gradle

        • Add within theandroid section:

          Gradle

            android {
                ...
                signingConfigs {
                    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
                    }
                }
            }
          

Before you proceed further and Generate the build file or release apk. You might want to change your app name or app icons or app version , for that refer to this article : Guide to how to change app name , icon and version of your apk with best solution.

  1. Generate the Release APK

    • Open a terminal in your project's root directory

    • Execute the build command:

      In Bash or any terminal of your choice.

      • For MacOS & Linux :

          cd android && ./gradlew assembleRelease
        
      • For Windows :

          cd android; ./gradlew assembleRelease
        
    • Find your APK: The signed APK will be in android/app/build/outputs/apk/release/app-release.apk

  2. To generate release AAB file for windows:

     cd android; ./gradlew bundleRelease
    

6. To clean the build directory :

        cd android; ./gradlew clean
  • Important Notes

    • Protect your keystore: Treat it like a highly sensitive asset. Loss or compromise means losing the ability to update your app.

    • TheassembleRelease task: This Gradle task cleans your project, builds it in release mode, and signs it with your configuration.

Did you find this article valuable?

Support Vishesh Tech by becoming a sponsor. Any amount is appreciated!

ย