This is the story of a very difficult installation on Ubuntu 18.04
Not everybody will experience such difficulties, but those who do will be happy to find here some hints on how to resolve issues (see the TROUBLESHOOTING section further down).
I am going to explain how to install React Native on Ubuntu (in particular Ubuntu 18.04) alongside Android Studio and how to get the emulator running and displaying your code.
You may want to take a few days off… No, kidding..
Installing React Native
First of all we need to install Node.js
Node.js like many other tools is pretty easy to install using the APT package manager:
$ sudo apt-get update $ sudo apt-get install nodejs
Next we install react-native-cli
$ sudo npm install -g react-native-cli
Often you will find this command online without “sudo” but I personally had to use it and I think this should be the correct way, otherwise getting some errors regarding Permissions
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
Now, install JDK 10 or higher
Have a look here for how it is done:
https://www.codebind.com/java-tutorials/install-java-jdk-10-ubuntu-18-04-ubuntu-16-04/
At last we are ready to install Android Studio
There are various methods for this but the one that seemed the most trustworthy to me was to download the package from this URL:
https://developer.android.com/studio/
and follow the instructions here:
https://developer.android.com/studio/install#linux
and also, here:
https://facebook.github.io/react-native/docs/getting-started
The last link will give you an exact description of the settings to choose while installing Android Studio. It is paramount to follow these instructions to the dot!
TROUBLESHOOTING
Good. If you followed the explanations and links above you should have your project directory for React Native set up and Android Studio running…
But, nothing is working, you are just getting these error messages..
1) Starting the emulator
This has to be understood.
First of all, have you created a virtual device? If not, go back to this link and follow the instructions to create your virtual device (emulator):
https://facebook.github.io/react-native/docs/getting-started
Once this is done, you need to “run” your device BEFORE launching the “react-native run-android” command which you will run in a terminal from within your React Native project.
2) Virtual Technologies / KVM
This should also help having things running faster.
The Virtual Technologies have to be activated in your BIOS. You may google how to access your BIOS and activate “Virtual Technologies”.
On top of that, you will need to add KVM.
KVM is an abbreviation for Kernel-based Virtual Machine.
In my case, I had to enter the following command (but you may google the right command for your Ubuntu version)
sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager
3) Unable to load script from assets index.android.bundle
“Wonderful!” I thought, .. and then came the next error inside my virutal device…
This I get every time I set up a new project. So here the solution:
From within your project directory, run these 2 commands
mkdir android/app/src/main/assets 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
(make sure first that the directory “android/app/src/main/assets/” does not exist)
4) This build could be faster, please consider using the Gradle Daemon
When running “react-native run-android” you might see this message appearing..
Follow the instructions here (or look for instructions corresponding to a current version at the time you are researching):
https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
5) adb server version (36) doesn’t match this client (40); killing…
This was at the time I run android, you might have different numbers there… The message appears, like above, while running “react-native run-android”.
You might want to do the following to install the newest version on your computer:
Go – for example – to your Download folder and..
wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip unzip platform-tools-latest-linux.zip sudo cp platform-tools/adb /usr/bin/adb sudo cp platform-tools/fastboot /usr/bin/fastboot
6) com.facebook.react.common.DebugServerException: facebook::react::Recoverable
Yes, no end to those errors!…
Anyway, this one looks terrifying, but just reload your device with a double-R and the screen should be cleared…
7) could not connect to development server
Last but certainly not least…
This one is for me perhaps the most annoying of the error messages. There can be many reasons for this.
- you have simply an error, some mis-configuration in your project
- clear the data of your virtual device (you can do this from within the Android Virtual Device Manager and use “Wipe Data”)
- log out of your Ubuntu account (or restart computer) and run everything again
- try this in your terminal:
adb reverse tcp:8081 tcp:8081
- or try this first:
adb kill-server
then this:adb start-server
Strangely enough, I could even do the following to solve the issue:
First, run this code: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Then, try to run “react-native run-android” again, and if still issue…
… go into the file /etc/sysctl.conf and remove the last line that was just added, then run “react-native run-android” again!
8) Still issues…
This is weird, I sometimes had the feeling that I just had to wait long enough and then suddenly the device was working.
But actually it would have been the last solution described in 7) that will have been the saving moment for me.
I hope you could find a solution for you in all this.
Patience is definitely a virtue here!
Leave a Reply