This is a step by step tutorial to set up yours react native app without using Android Studio IDE. We are going to use android command line tools to set up our react native application.
First download this tools to your machine.
Once you downloaded the above tools now we will create a simple react native app. Later on I will show you how to build the app (.apk file) using android command line tools that we have downloaded in the first step.
To create react native app you must have below software’s installed on your machine.
- node.js (Download)
Continue to the next step once you installed node.js
- Create a sample folder called ‘react-native-app’ (You can name it whatever you want).
- Now install react-native command line tool.
You can install react-native command line tool by typing the below command.
Open terminal and type
npm install -g react-native
Once react-native command line tool is installed we will set up our simple project.
Open terminal and navigate to ‘react-native-app’ folder which we created earlier.
Now we will run the below command for initial setup of react native code.
react-native init sample-app
This will create a `sample-app` folder which has initial code which you can run and see on your phone without writing any addition code.
Now you need to install the dependencies before you build the project. In order to do that run this below command.
The above command will install all the dependencies required which is defined in `package.json` file.
Now connect your mobile to your machine using USB cable. Make sure that you enabled `Developer options` in your mobile.
How to enable Developer options?
Go to settings > About Phone > Build Version.
Click on Build Version 7 times then it will enable Developer options in your main setting menu.
Check whether your laptop/desktop has adb installed. If you have not installed adb it cannot recognise your device and you cannot install the app using USB debugger mode.
Now run below command to run app on your phone.
Once you run the above command you might get some errors like local.properties not set. To fix that error just check for the folder called `android` in your project and navigate into it and create a file called ‘local.properties’.
Now open the file and provide the path for `android tools` which you downloaded in first step. Refer below.
Rename based on your sdk tools download location.
Now again run the command
If you are getting any errors like license is not installed just do this fix.
Go to sdk-tools and navigate to tools/bin/ folder
Now run the below command
Just say ‘Y’ for all.
Now again run the below command
If everything went right you can see an .apk file is generated in android/app/build/outputs/apk/app-debug.apk
You can also see the app running on you mobile which you connected using USB.
If the app is not loading throwing some error with red screen. Run the below command
adb reverse tcp:8081 tcp:8081
If you are still facing any issue please let me know in comments. I will help you to set it up.
If you just need to build the app without connecting your device you need to bundle the app before building it.
You can do that by running the following command
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
Now again run below command to generate apk file.
That’s all you got your apk file generated. This is how you can build your app with out using Android studio IDE.
Thanks for reading. Please share this tutorial.