Home » React-native » How to create build React-native android

How to create build React-native android

Beginner React-native

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

How to create a test build React-native android

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 🙂

 

Related Posts

4 thoughts on “How to create build React-native android

    1. Hi,

      You can first check list of ADB devices running on your machine using following command.

      $ adb devices

      Then, Use following command to run build on particular emulator

      $ react-native run-android –deviceId=DEVICE_ID

Leave a Reply

Your email address will not be published. Required fields are marked *