无法在Mac上第一次运行用于android的react-native app

时间:2017-11-25 15:04:25

标签: reactjs react-native react-native-android

我正在尝试在macbook上为android版本运行react-native应用程序。所以我已经按照所有步骤在这里设置了机器上的环境:

https://facebook.github.io/react-native/docs/getting-started.html

我已成功安装Android Studio,Android SDK, JDK, Node, NPM, Watchman, Homebrew

  • javac -version:9
  • node -v:v8.9.1
  • npm -v:5.5.1
  • 守望者版本:4.9.0

当我尝试使用命令

运行应用程序时
react-native run-android

我收到了这个错误:

Starting JS server...
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/aman/.gradle/wrapper/dists/gradle-2.14.1-all/8bnwg5hd3w55iofp58khbp6yv/gradle-2.14.1/lib/gradle-base-services-2.14.1.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

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

Total time: 9.925 secs
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

enter image description here

2 个答案:

答案 0 :(得分:1)

是的,据@Sam Hanley说,这是java版本更新的问题。因此,由于担心版本更新/降级,我们可以通过以下过程继续解决此问题;

  1. 首先,更新gradle-wrapper.properties中的 distributionUrl 即:位于此路径中;
  2.   

    PROJECT_PATH /机器人/ gradle这个/包装/ gradle-wrapper.properties

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-rc-2-all.zip
    
    1. 使用已安装的android studio应用程序路径设置 $ JAVA_HOME 环境变量(应安装Android studio)
    2.   

      导出JAVA_HOME =“/ Applications / Android   Studio.app/Contents/jre/jdk/Contents/Home“

      (PS:macOS解决方案)

      希望这有帮助!

答案 1 :(得分:0)

通过执行以下操作,我能够解决这个问题:

  1. 修改False
  2. path_to_your_project/android/gradlew更改为DEFAULT_JVM_OPTS=""