React Native error: “Could not determine java version from '9.0.1'.”

前端 未结 11 1724
悲&欢浪女
悲&欢浪女 2020-11-28 03:50

I\'m working on MacOS and just starting with react-native.

One of the first steps to get started is to run: react-native run-android or

相关标签:
11条回答
  • 2020-11-28 04:03

    Really the fastest way to get around this error is to use JDK 8. Except when you really need to use JDK9.

    http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    Don't forget to change your enviroment variable JAVA_HOME to the new JDK version!

    0 讨论(0)
  • 2020-11-28 04:12
    vi ~/.bash_profile
    

    Then add the following lines:

    export ANDROID_HOME=$HOME/Library/Android/sdk
    export PATH=$PATH:$ANDROID_HOME/tools
    export PATH=$PATH:$ANDROID_HOME/tools/bin
    export PATH=$PATH:$ANDROID_HOME/platform-tools
    export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
    

    Now source the file to make the above changes effective in the current shell:

    source ~/.bash_profile 
    
    0 讨论(0)
  • 2020-11-28 04:12

    I was getting this error, but for a more recent version of Java - 10.0.2.

    To fix my error, I followed the steps mentioned by @Blacktoviche in this Github issue: https://github.com/facebook/react-native/issues/17688

    When I opened the android folder inside my project via Android Studio, I was prompted with Android Gradle plugin update recommended. At the time, I was following a slightly outdated tutorial that told me to click Don't remind me again for this project.

    However, as @Blacktoviche recommended in the github issue linked above, sometimes it's necessary to update the Gradle plugin. After updating, I also had to click Install Build Tools 27... and sync project (I don't remember the exact version).

    After I followed these steps, I was able to successfully run my react native app on the Android Studio emulator.

    Hope this helps someone!

    0 讨论(0)
  • 2020-11-28 04:16

    If you are using windows; Make sure you add your jdk path to the Environment path variable. Then open your android folder from your react native project into android studio. It will update necessary things for you automatically.

    0 讨论(0)
  • 2020-11-28 04:19

    Make sure that you have JDK8 installed and then set JAVA_HOME into JDK8

    for example:

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

    or use .bash_* files to set this variable

    0 讨论(0)
提交回复
热议问题