无法让 React Native 在 Ubuntu 上工作

Can't get React Native to work on Ubuntu

我正在尝试在 Ubuntu 16.04 上安装 React Native 运行ning。我在我的 Windows 机器上将它与 create-react-native-app 和 expo 一起使用,同时使用 Android Studio 虚拟设备和通过 USB 连接的平板电脑。现在我有一台新的 Ubuntu 笔记本电脑和 Ubuntu 我的电脑上的双启动,我试图在那里设置它但失败得很惨。

让我们来处理笔记本电脑。按照说明,我安装了 Expo 和 Genymotion。世博会永远无法正常运作,所以现在我只是想让它更直接地进行。我还安装了 Java 8 和 watchman。我已经安装并尝试了太多的东西。到目前为止,我已经投入了大约 20 个小时。

以下是我尝试开始操作时发生的情况。

如果我插入我的平板电脑,我得到:

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

(附带说明一下,我的 adb 服务器似乎总是过时的。)当我尝试 运行 由 react-native-cli[= 安装的默认代码时123=] 通过 运行ning react-native run-android,我得到:

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

我研究了这些错误,但找不到有效的解决方案。

如果我启动 Android Studio 虚拟设备(N6,API 23),它会启动。 adb devices 让我:

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

当我尝试 运行 应用时:

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

同样,我还没有找到解决方案。

当我尝试通过 genymotion 做同样的事情并做 adb devices 时,我得到:

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: 

我尝试 运行 应用程序时得到相同的结果。

有什么想法我接下来应该尝试什么吗?请记住,我对 linux 还是很陌生,所以请具体说明。如果你告诉我,“只需更改 Fetzer 配置文件中的 RX74 常量”,我就不会知道你在说什么。 (我对 linux 的建议有过糟糕的体验,这些建议假设我知道系统上的每个文件是什么以及在哪里可以找到它。)

提前致谢。

附录 1 @Vigas Deep:

当我检查时 which -a adb:

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

所以我有不止一个。我会弄清楚为什么一个被调用两次,现在我只是重命名它,现在我得到:

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

我启动 Android Studio 虚拟设备并检查它:

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

当我尝试 运行 RN 入门应用时:

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

有趣的是,当我尝试重新启动 adb 服务器时,我得到:

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

SDK中的adb没有这些命令吗?

为了好玩,我重新启动并尝试插入平板电脑:

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

(但由于某些原因只有插入USB2端口时才会出现,位置非常不方便。)

当我尝试 运行 RN 项目时:

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

抱歉,我目前能做的测试就这些了。还有其他想法吗?

附录 2 @Vigas Deep:

“只是为了确保它使用位于 sdk 内部的 adb;现在使用此命令:/home/kevin/Android/Sdk/platform-tools/adb devices”

好的,无论我使用哪个,我都会得到相同的结果。

"并且不要将 sudo 用于 adb 命令,因为我们不会 运行 react-native 运行-android 作为 sudo。"

好的。我看到的所有示例都使用 sudo 来启动和终止 adb 服务器。 St运行gely,现在 没有 sudo 但没有。以前我觉得是相反的,但是我好久没试过所以不能确定。

“另外;您使用的是 openJDK 还是 oracleJDK;您是如何安装 JDK 的?”

我以为我记得访问过 Oracle 站点,但是当我执行“java -version”时,我得到:

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)

这似乎表明情况并非如此。我应该改变它吗?

附录 3 @Vigas Deep:

好的,我查看了如何删除 openjdk 并按照它进行操作。为了确定,我找到了有关如何安装 jdk8 的说明。当我尝试 运行 RN 应用程序时,我遇到了同样的错误。当我检查 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)

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

当我检查 jvm 文件夹时:

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

以防万一,这是我当前的 $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

还有其他想法吗?我错过了什么吗? (很有可能)

附录 4 @Vigas Deep:

OK,就这样彻底删除了Java,主要是下面this.

我使用 this 重新安装了它。

在对 genymotion 进行了一些修改之后,我能够在 create-react-native-app 上启动一个应用程序,该应用程序 运行 在 genymotion 上。

谢谢@vigas-deep。如果你在奥克兰,我欠你一杯啤酒,或者任何你喜欢的饮料。谢谢!

我在 Ubuntu 和其他基于 Linux 的操作系统方面有八年的经验。

我认为问题在于您有多个版本的 ADB。

运行下面的命令就知道对不对了

which -a adb

如果您有多个版本的 adb,只需保留 android sdk 和 remove/rename 其他版本中的 adb 版本。

如果您再次需要这些可执行文件,最好重命名。

如果需要,我很乐意提供更多帮助。