Search code examples
androidandroid-studioubuntureact-nativegenymotion

Can't get React Native to work on Ubuntu


I am trying to get React Native running on Ubuntu 16.04. I have used it with create-react-native-app and expo on my Windows machine with both the Android Studio virtual device and a tablet connected by USB. Now I have a new Ubuntu laptop and a Ubuntu dual boot on my PC and am trying to set it up there but have failed miserably.

Let's deal with the laptop. Following the instructions, I have installed Expo and Genymotion. Expo could never work right so now I'm just trying to get it going more directly. I have also installed Java 8 and watchman. I've installed and tried too many things to mention. I've put in about 20 hours so far.

Here is what happens when I try to start things.

If I plug in my tablet, I get:

kevin@kevin-Kudu:~/programming/rn4$ adb devices
adb server is out of date.  killing...
* daemon started successfully *
List of devices attached 
5205132d4f9011af    device

(As a side note, it seems that my adb server is always out of date.) When I try to run the default code installed by react-native-cli by running react-native run-android, I get:

kevin@kevin-Kudu:~/programming/rn4$ react-native run-android
Scanning folders for symlinks in /home/kevin/programming/rn4/node_modules (9ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

I've researched these errors and can't find a solution that works.

If I start an Android Studio virtual device (N6, API 23), it starts up. adb devices gets me:

kevin@kevin-Kudu:~/programming/rn4$ adb devices
adb server is out of date.  killing...
* daemon started successfully *
List of devices attached 
5205132d4f9011af    device

When I try to run the app:

kevin@kevin-Kudu:~/programming/rn4$ react-native run-android
Scanning folders for symlinks in /home/kevin/programming/rn4/node_modules (9ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Again, I haven't been apple to find a solution.

When I try to do the same thing through genymotion and do adb devices, I get:

kevin@kevin-Kudu:~/programming/rn4$ adb devices
adb server is out of date.  killing...
cannot bind 'tcp:5037'
ADB server didn't ACK
* failed to start daemon *
error: 

I get the same result when I try to run the app.

Any ideas what I should try next? Please bear in mind that I am still fairly new to linux so please be specific. If you tell me, "Simply change the RX74 constant in the Fetzer config file" I'm not going to have any idea what you are talking about. (I've had bad experiences with linux advice that assumes that I know what every file on the system is and where to find it.)

Thanx in advance.

ADDENDUM 1 @Vigas Deep:

When I check which -a adb:

kevin@kevin-Kudu:~$ which -a adb
/usr/bin/adb
/usr/bin/adb
/home/kevin/Android/Sdk/platform-tools/adb

So I have more than one. I'll figure out why one is getting called twice, for now I just rename it, and now I get:

kevin@kevin-Kudu:~$ which -a adb
/home/kevin/Android/Sdk/platform-tools/adb

I fire up the Android Studio virtual device and check it:

kevin@kevin-Kudu:~$ adb devices
List of devices attached
emulator-5554   device

And when I try to run a RN starter app:

kevin@kevin-Kudu:~/programming/rn4$ react-native run-android
Scanning folders for symlinks in /home/kevin/programming/rn4/node_modules (18ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Interestingly, when I try to restart the adb server, I get:

kevin@kevin-Kudu:~/programming/rn4$ sudo adb kill-server && adb start-server
[sudo] password for kevin: 
sudo: adb: command not found

Does the adb in the SDK not have those commands?

Just for kicks, I reboot and try pluggin in a tablet:

kevin@kevin-Kudu:~$ adb devices
List of devices attached
5205132d4f9011af    device

(But for some reason only shows up when plugged into the USB2 port, very inconveniently located.)

When I try to run the RN project:

kevin@kevin-Kudu:~/programming/rn4$ react-native run-android
Scanning folders for symlinks in /home/kevin/programming/rn4/node_modules (21ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Sorry, that's all the testing I can do for now. Any other ideas?

ADDENDUM 2 @Vigas Deep:

"just to make sure that its using the adb located inside sdk; use this command for now: /home/kevin/Android/Sdk/platform-tools/adb devices"

OK, I get the same result whichever I use.

"and do not use sudo for adb command because we are not going to run react-native run-android as sudo."

OK. All the examples I saw used sudo to start and kill the adb server. Strangely, now it works without sudo but not with. Before, I think it was the opposite, but I haven't tried it without in a long time so I can't be sure.

"Also; are you using openJDK or oracleJDK ; how did you install the JDK?"

I thought I remembered going to the Oracle site, but when I do "java -version", I get:

kevin@kevin-Kudu:~/programming/rn4$ java -version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-3)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

This would seem to indicate otherwise. Should I change it?

ADDENDUM 3 @Vigas Deep:

OK, I looked up how to remove openjdk and followed it. I found instructions about how to install the jdk8, just to be sure. I am getting the same error when I try to run the RN app. When I check java -version:

kevin@kevin-Kudu:~/programming/rn4$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

and

kevin@kevin-Kudu:~/programming/rn4$ readlink -f $(which java)
/usr/lib/jvm/java-8-oracle/jre/bin/java

When I check the jvm folder:

kevin@kevin-Kudu:/usr/lib/jvm$ ls
java-8-oracle

Just in case, here is my current $PATH:

kevin@kevin-Kudu:/usr/lib/jvm$ echo -e ${PATH//:/\\n}
/home/kevin/bin
/home/kevin/.local/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/home/kevin/bin
/usr/bin
/snap/bin
/usr/lib/jvm/java-8-oracle/bin
/usr/lib/jvm/java-8-oracle/db/bin
/usr/lib/jvm/java-8-oracle/jre/bin
/home/kevin/Android/Sdk/tools
/home/kevin/Android/Sdk/platform-tools

Any other ideas? Am I missing something? (highly likely)

ADDENDUM 4 @Vigas Deep:

OK, so completely removed Java, mainly following this.

I reinstalled it using this.

After some monkeying around with genymotion, I was able to get an app started on create-react-native-app that ran on genymotion.

Thank you @vigas-deep. If you're even in Oakland, I owe you a beer, or whatever your beverage of choice is. Thanx!


Solution

  • I have eight years of experience with Ubuntu and other Linux based OSes.

    I think the problem is you are having multiple versions of ADB.

    run the following command to know if that's right.

    which -a adb

    And if you have multiple versions of adb, just keep the adb version which is inside your android sdk and remove/rename others.

    prefer rename just incase if you need those executables again.

    I'd be happy to help more if needed.