无法通知项目评估侦听器> javax/xml/bind/annotation/XmlSchema

Tia*_*vêa 5 android gradle android-sdk-tools android-studio react-native

我试图首先运行一个react-native应用程序react-native run-android.我希望它可以工作,就像我打电话时一样react-native run-ios.堆栈中有很多用户遇到同样的错误,"无法通知项目评估监听器".

观察到的行为

> react-native run-android
Scanning folders for symlinks in /Users/tiagogouvea/www/go-along/mobile/node_modules (12ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod (file:/Users/tiagogouvea/.gradle/wrapper/dists/gradle-4.0-milestone-1-all/2rnr7rhi2zsmkxo9re7615fy6/gradle-4.0-milestone-1/lib/gradle-base-services-4.0.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /Users/tiagogouvea/Library/Android/sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > javax/xml/bind/annotation/XmlSchema

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 4s
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/android-setup.html
Run Code Online (Sandbox Code Playgroud)

环境

  • npm ls react-native-scripts:空的
  • npm ls react-native:react-native@0.50.3
  • npm ls expo:空的
  • node -v:v8.0.0
  • npm -v:5.5.1
  • yarn --version:1.2.1
  • watchman version:4.9.0

    1. 操作系统:macOs 10.12.6
    2. 手机/模拟器/模拟器和版本:Genymotion图像

use*_*408 7

正如对OP 提交的错误的评论中所述,Gradle 似乎在 Java 9 或更高版本上存在问题。

您需要安装 JDK 8(JRE 是不够的,8 以后的版本将无法运行)并告诉 Gradle 使用它,而不是您系统上的默认 Java 版本。

在我的情况下(运行 Ubuntu 18.04),这需要安装openjdk-8-jdk(我已经有 JDK 11 和 JRE 8 但没有 JDK 8)。

您可以通过多种方式告诉 Gradle 使用 JDK 8(在所有示例中,将路径替换为 JDK 安装的实际路径;此处显示的方法适用于 Ubuntu 18.04 amd64):

  1. 使用选项运行 Gradle

    -Dorg.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
    
    Run Code Online (Sandbox Code Playgroud)
  2. 确保~/.gradle/gradle.properties包含该行

    org.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在您build.gradle包含以下几行:

    compileJava.options.fork = true
    compileJava.options.forkOptions.executable = /usr/lib/jvm/java-8-openjdk-amd64
    
    Run Code Online (Sandbox Code Playgroud)

这帮助我在不同的项目中摆脱了同样的错误。