DEV Community

Cover image for Android Release and Publishing to Google Play Store
Selva kumar
Selva kumar

Posted on

Android Release and Publishing to Google Play Store

Preparing React Native App for Android Release on Mac
When your React Native Application is ready for release to the Android Platform, you need to perform the following steps to create the .aab file or Android App Bundle which contains your compiled code and resources and you can upload to the Play Store. The APK generation and signing is done by Google Play.

Generating an upload key

Open Terminal and check the Java Home Path:

/usr/libexec/java_home
Enter fullscreen mode Exit fullscreen mode

cd to the path displayed as shown in the image.

Run the keytool command as shown using sudo to generate the keystore and alias as shown below:

sudo keytool -genkey -v -keystore some-helper-key.keystore -alias some-helper-key-alias -keyalg RSA -keysize 2048 -validity 10000
Enter fullscreen mode Exit fullscreen mode

As shown in the screenshot, answer the questions that pop and your Keystore will be generated under the Java Home folder.

Copy that Keystore file and paste it in your Android folder under app in your React Native Project.

Modify the android/gradle.properties file and add:

MYAPP_UPLOAD_STORE_FILE=some-helper-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=some-helper-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=***
MYAPP_UPLOAD_KEY_PASSWORD=***
Enter fullscreen mode Exit fullscreen mode

You might not want to store the passwords directly in the above configuration and store them in the keychain Access App, then the last 2 password configs are not required.

Add the Release signingconfig section to the android/app/build.gradle file:

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
            }
        }
    }
Enter fullscreen mode Exit fullscreen mode

cd to the Android folder and run:

./brew gradlew bundleRelease
Enter fullscreen mode Exit fullscreen mode

The .aab file is generated as: android/app/build/outputs/bundle/release/app-release.aab

Now, this is ready to be uploaded to the Play Store.

Issues Faced:

Resource and asset merger: Duplicate resources

The above error occurred for files under drawable folder, app.json, node_modules_reactnativevectoricons_glyphmaps_materialcommunityicons.json, etc.

Go to android/app/src/main/res and delete all the directories starting withdrawable and the above-mentioned .json files. Do not delete the raw folder if it contains any resources.

If you want to directly test the Release version on your device, run the following command under the Root folder of the Project:

react-native run-android --variant=release
Enter fullscreen mode Exit fullscreen mode

You can install the bundle tool on Mac:

brew install bundle tool
To extract the APK directly from the .aab file, run the following commands:

bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
Enter fullscreen mode Exit fullscreen mode

If you want to test it on a device, then also include the App signing information:

bundletool build-apks --bundle=/MyApp/apprelease.aab --output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=pass:***
--ks-key-alias=MyKeyAlias
--key-pass=pass:***
Enter fullscreen mode Exit fullscreen mode

Please note that the .aab file should not contain hyphens else it’ll give a file not found error.

If you want to generate a single Universal apks file, run the below command. Copy the .aab and .keystore files to the folder from where you’ll run bundle tool using terminal:

bundletool build-apks --bundle=MyApp.aab --output=MyApp.apks --mode=universal --ks=my-key.keystore --ks-pass=pass:**** --ks-key-alias=my-key-alias --key-pass=pass:****
Enter fullscreen mode Exit fullscreen mode

Change the extension .apks to .zip and extract the universal.apk file. You can rename this file and transfer it to your Android device for installation.

You can also install the .apks directly to your connected device using the bundle tool:

bundletool install-apks --apks=MyApp.apks
Enter fullscreen mode Exit fullscreen mode

Discussion (0)