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

Failed to notify project evaluation listener > javax/xml/bind/annotation/XmlSchema

我试图首先 运行 一个带有 react-native run-android 的反应本机应用程序。我希望它能正常工作,就像我调用 react-native run-ios 时一样。 堆栈中有很多用户出现相同类型的错误,"Failed to notify project evaluation listener"。

观察到的行为

> 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

环境

正如 OP 对 bug 的评论中提到的,Gradle 似乎对 Java 9 或更高版本有问题。

需要安装JDK8(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
    
  2. 确保 ~/.gradle/gradle.properties 包含行

    org.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
    
  3. 在您的 build.gradle 中包含以下行:

    compileJava.options.fork = true
    compileJava.options.forkOptions.executable = /usr/lib/jvm/java-8-openjdk-amd64
    

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

其实我是运行Java9,运行一个java --version给了我:

$: java --version java 9 Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

彻底解决 我做到了:

1) 删除了 Java 9:

sudo rm -rf "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"  
sudo rm -rf "/Library/PreferencePanes/JavaControlPanel.prefPane"  
sudo rm -rf "~/Library/Application Support/Java"

2) 安装回 Java 8 - download here

3) 添加 JAVA_HOME 行到我的 bashfile (~/.bash_profile):

nano ~/.bash_profile  
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home

* 注意在路径

上使用正确的jdk版本

而且,现在一切正常。感谢@user149408 的帮助!

我已经通过清除所有 Gradle 缓存解决了这个问题,停止了 Gradle 守护进程,并使用以下命令成功创建了一个新版本。确保您的当前目录是 android.

rm -rf ~/.gradle/caches && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease