Building APKs in React Native 🛠️
What is an APK?
APK stands for Android Package Kit, the format used to distribute and install software on Android. If you're anything like me you used to circumvent paying for apps on the Play Store by downloading these from, admittedly sketchy, 3rd party websites.
Debugging Builds
Prerequisite
You'll need to enable debugging on your device (under developer options).
*if you don't see developer settings go to About Phone -> Software information -> Tap Build number 7 times
What is a debug build?
A debug build generates the .apk which can be installed on the device or emulator you're using and allows you to test drive your app.
Building
- Run the following
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
- From the android folder run
./gradlew assembleDebug
And Boom! The .apk will be in the build/outputs/apk/debug/ directory!
Release Builds
What is a release build?
A release build generates a full fledged .apk which can be sent and installed on your device or even uploaded to the play store.
Building
- Use keytool to generate a keystore
keytool -genkey -v -keystore your_key_name.keystore -alias your_key_alias -keyalg RSA -keysize 2048 -validity 10000
- Enter a password (be sure to remember this)
- Copy the .keystore file you generated to the android/app directory
- Open the android\app\build.gradle config
- Add these
android { .... signingConfigs { release { storeFile file('your_key_name.keystore') storePassword System.console().readLine("\nKeystore password:") keyAlias System.console().readLine("\nAlias: ") keyPassword System.console().readLine("\nAlias password: ") } } buildTypes { release { .... signingConfig signingConfigs.release } } }
- Then from the android directory run
./gradlew assembleRelease
And there ya go! android/app/build/outputs/apk/ will contain your .apk