How to create build React-native android
Hi Guys, In this article, we are going to discuss How to create a test build React-native android, as a react-native developer we have to give test build to the client for testing. Android developers mostly use Android studio IDE to develop applications and create a build using Android studio but For React-native we have to run some command to create a build in react-native. let’s start with an example
Agenda:
1. Create index.android.bundle
2. Update index.android.bundle file
3. Create final Android build
1. Create index.android.bundle
This file is very important while building a react-native Android application. the location of this file is ProjectName\android\app\src\main\assets\index.android.bundle if this file isn’t available then you can create this file manually and update later using the following 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
this command need to run every time before creating a build. this command builds all javascript code and update index.bundle.android file. if you want to run this command automatically then you have to add this command in package.json in script section like below
{ "name": "ProjectName", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest", "android-linux": "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" }, }
You can set –dev true for display developer option to developers if you are creating release build set to –dev false
after completing this command next step is to build android project
2. Build an android project
Goto Android directory because we are building android project
cd Android/
Run the following command to build debug build
./gradlew assembleDebug // for linux gradlew assembleDebug // Windows
Goto the following location and check .apk file
ProjectName\android\app\build\outputs\apk\debug\app-debug.apk
You can install this app-debug.apk in your device
To create a release build for the client you can use the following command to build the App
./gradlew assembleRelease // for linux gradlew assembleRelease // Windows
3. Getting any error
If you will get some error gradlew assembleRelease not updating APK output file then you have to clean Android project using the following commands
Goto Android directory
cd Android/
Clean Android project
./gradlew clean // for Linux gradlew clean // for windows
Build android project again
./gradlew assembleRelease // for linux
Thank you 🙂
Hi еveгуone, it’s my first pay a quick visit at this web page,
and post is really frսitfuⅼ in favor of me, keep up posting these articles or reviews.
Thanks 🙂