0
0
React Nativemobile~10 mins

Android build and signing in React Native

Choose your learning style9 modes available
Introduction

Building and signing an Android app prepares it for release. Signing proves the app is from you and keeps it safe.

When you want to share your app with friends or testers.
Before uploading your app to the Google Play Store.
To make sure your app can be updated securely later.
When you want to create a final version of your app.
To protect your app from being changed by others.
Syntax
React Native
1. Generate a signing key:
keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

2. Create a file android/gradle.properties with:
MYAPP_UPLOAD_STORE_FILE=my-release-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=your-store-password
MYAPP_UPLOAD_KEY_PASSWORD=your-key-password

3. Edit android/app/build.gradle to add signing config:
android {
  signingConfigs {
    release {
      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
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

4. Build the signed APK:
cd android
./gradlew assembleRelease

Use keytool from Java to create your signing key.

Keep your passwords safe and never share your keystore file publicly.

Examples
This command creates a new keystore file with a key alias and password prompts.
React Native
keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
These lines in gradle.properties store your signing info securely for the build.
React Native
MYAPP_UPLOAD_STORE_FILE=my-release-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=your-store-password
MYAPP_UPLOAD_KEY_PASSWORD=your-key-password
This snippet in build.gradle tells Gradle to use your signing info when building the release APK.
React Native
android {
  signingConfigs {
    release {
      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
    }
  }
}
This command builds the signed APK ready for release.
React Native
./gradlew assembleRelease
Sample App

This script shows the main steps to create a signing key and build a signed APK for your React Native Android app.

React Native
# This is a shell script example to build and sign React Native Android app

# Step 1: Generate keystore (run once)
keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

# Step 2: Create or edit android/gradle.properties with:
# MYAPP_UPLOAD_STORE_FILE=my-release-key.keystore
# MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
# MYAPP_UPLOAD_STORE_PASSWORD=your-store-password
# MYAPP_UPLOAD_KEY_PASSWORD=your-key-password

# Step 3: Build signed APK
cd android
./gradlew assembleRelease

# The signed APK will be at android/app/build/outputs/apk/release/app-release.apk
OutputSuccess
Important Notes

Always back up your keystore file and passwords. Losing them means you cannot update your app.

Use strong passwords to protect your keystore.

Test your signed APK on a device before publishing.

Summary

Building and signing prepares your app for safe release.

Generate a keystore, configure Gradle, then build the signed APK.

Keep your signing keys and passwords secure to update your app later.