Preparing an Android App Bundle (AAB) on a Mac M1 with macOS Sonoma 14.4 involves a series of important steps. This guide provides a detailed walkthrough for developers using React Native, highlighting the creation and signing of a keystore file.
Steps for Creating an Android App Bundle
1. Install Required Tools:
Ensure installations of Node.js, Watchman, JDK, and Android Studio are up to date. Set up the Android SDK and necessary environment variables on your Mac.
Follow the instructions in the article below to set up a React Native codebase on your macOS. It provides a step-by-step guide.
2. Generate a Keystore Using Keytool:
Open the terminal and run:
keytool -genkey -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
Fill in the required information for the keystore including password, your name, organizational unit, organization name, city, state, and country code. Notably, I have chosen ‘Zahir1#’ as the keystore password. This generates a my-upload-key.keystore
file, which you should then move to your project’s android/app/
directory.
3. Configure Gradle Properties:
Add your keystore details to gradle.properties
in your android folder of your project:
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=Zahir1#
MYAPP_UPLOAD_KEY_PASSWORD=Zahir1#
4. Set Up android/app/build.gradle
:
Configure your build script by setting the signingConfigs
under the android block for the release build:
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
...
}
}
}
5. Change version of app:
Update your apps versionName
and versionCode
in android/app/build.gradle:
defaultConfig {
applicationId "myappname"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "0.1.0"
}
6. Build the Android App Bundle:
Navigate to your project’s Android directory:
cd android
./gradlew clean
./gradlew bundleRelease
This generates the AAB file in android/app/build/outputs/bundle/release/app-release.aab
.
FAQs
- What is a keystore? A keystore is a binary file that holds a set of private keys used to sign your Android app. Signing your app verifies your identity as the developer and secures app updates.
- Why choose AAB over APK? An AAB allows for more efficient distribution as it lets Google Play optimize the app’s APKs for the various device configurations users have, reducing app size and simplifying the release process.
- How to securely manage keystore information? Never store passwords in plaintext within the codebase. Use environment variables or secure vault solutions to manage sensitive information securely.
Conclusion
Properly setting up and signing your Android App Bundle is essential for securing your app’s integrity and facilitating its distribution on the Google Play Store. This guide ensures your React Native app is well-prepared for release, covering everything from environment setup to keystore generation and Gradle configuration.