What is an .apk file?
An Android Package Kit
APKis the package file format used by the Android Operating System for ~Distribution~ and Installation of Mobile Apps. It is similar to the
.exefile you have on Windows Operating System, a
.apkfile is for Android.
Do You Know Why I Cut The
I Cut that Because As Per New Google Play Guidelines, The New Format to Distribute Apps on the Play Store is an
AABFile. I will Write a Blog Post on How to Generate AAB for RN (React Native App) Soon.
.apk file will allow you to install and test your app before publishing to app stores. Mind you, this is not yet ready for publishing, and there are quite a few things you’ll need to do to before you can publish. Nevertheless, it’ll be useful for initial distribution and testing.
You’ll need to enable debugging options on your phone to run this type of apk.
react-native version > 0.58
- Go to the root of the project in the terminal and run the below command:
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
- Go to
- Now in this android folder, run this command
- There! you’ll find the apk file in the following path:
You will need a Java generated signing key which is a keystore file used to generate a React Native executable binary for Android. You can create one using the
keytool in the Terminal with the following command:
keytool -genkey -v -keystore your_key_name.keystore -alias your_key_alias -keyalg RSA -keysize 2048 -validity 10000
Once you run the keytool utility, you’ll be prompted to type in a password.
Make sure you Remember the Password!
You can change
your_key_name with any name you want, as well as
your_key_alias. This key uses
2048, instead of default
1024 for Security Reasons.
Firstly, you need to copy the file
your_key_name.keystore and paste it under the
android/app directory in your React Native project folder.
mv my-release-key.keystore /android/app
You need to open your
android\app\build.gradle file and add the keystore configuration. There are two ways of configuring the project with keystore. First, the common and unsecured way:
This is not a good security practice since you store the password in plain text. Instead of storing your keystore password in
.gradle file, you can stipulate the build process to prompt you for these passwords if you are building from the command line.
To prompt for password with the Gradle build file, change the above config as:
storePassword System.console().readLine("\nKeystore password:")
keyAlias System.console().readLine("\nAlias: ")
keyPassword System.console().readLine("\Alias password: ")
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
Place your Terminal Working Directory to
android and Build The
cd android && gradlew assembleRelease
cd android && ./gradlew assembleRelease
As a result, the APK creation process is done. You can find the generated APK at
android/app/build/outputs/apk/app-release.apk. This is the actual app, which you can send to your phone to install on it, but you need an
AAB File to Publish Your App to the Google Play Store.
🎉 Congratulations, you’ve just generated a React Native Release Build APK for Android.