React Native Android setup
Created 16 June 2020
Updated 17 June 2020
Programming computers is hard. We’re reminded of that every day we sit down to work. But before you can even get to programming, you have to set up your computer so that the program can have a chance to run. This can be tricky, depending on matching up operating systems, packages, and versions of software.
First, follow the instructions on React Native's site to install the software packages needed to develop in Android on my Mac. Yes, developing for Android on a Mac. Sometimes you gotta do what you gotta do.
Next, if you’re plugging into an existing project is to run npm install in the terminal from the project’s directory, so you have all the packages up to date.
Then, type npm run android to compile and run the project. If everything is in order, the application will run. For me, though, that wasn’t the case. My terminal filled with errors. If that happens to you, here are some things to check out. They are problems that I had, and solving them helped me get React Native working on my Mac:
- Your React Native project should have a directory in the project’s root called “android”. In there put a file called “local.properties” with the following line: sdk.dir = /Users/YOUR_NAME/Library/Android/sdk substituting YOUR_NAME with your username. This lets the app know where to find the software development kit (SDK) it needs.
- Run export ANDROID_HOME=~/Library/Android/sdk in the app’s root directory. Similar to the above, tells the app where to look for the software development kit, basically a collection of software to assist in developing Android applications. I find myself having to do this frequently, especially when running the application for the first time after opening the terminal.
- Accept all the SDK licenses. You can find them in Android Studio’s preferences:
- Specifically, you want to check Android SDK Command-line Tools (latest) and hit apply, so that you can accept the tools’ licenses.
- Generate a keystore with keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 in the app subdirectory (in the android folder referenced earlier). This is where authorization and security certificates are kept.
- Create the tools.jar file following Nathan Loterio's answer to this Stack Overflow question
With those you should solve the problems in environment setup and start developing. I hope this post helps!
Further reading. The solutions above were in the following StackOverflow pages: