Could not find tools.jar React Native Android In w

2020-05-22 07:30发布

问题:

guys . i just try to install react native in my laptop. i've followed all setup instruction but i stiil get those error .

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar

i used genymotion with os version 5.1.0, i've setup environment variable for android_home. Any idea what i miss here ?

回答1:

Setting the missing "JAVA_HOME" system environment variable worked for me.

  • Press WIN+Pause on keyboard.
  • Click advanced system settings.
  • Click "Environment variables".
  • Click "New" under "System variables".
  • Type "JAVA_HOME" in the Variable name field.
  • Type the path to the JDK in the Value field. For me the correct path with short filename was "C:\PROGRA~1\Java\jdk1.8.0_66". Your path will vary depending on the installed version.
  • Click OK, and OK in previous window too.
  • Restart any command prompts or restart the computer.
  • react-native run-android worked fine after that.


回答2:

Setting up appropriate JDK (not JRE. JRE does not have tools.jar) version (E.g. JDK 1.7x) path as the JAVA_HOME would resolve this issue.

Please check your computer's environment variables and set JAVA_HOME if it has not already been setup.



回答3:

If you have the Android Studio embedded JDK, then it may cause conflicts. A workaround for this problem I've found is setting your JAVA_HOME to the default JDK location specified in Android Studio.

  1. Open Android Studio
  2. Press Ctrl+Alt+Shift+S to open Project Structure window.
  3. Set your JAVA_HOME environment variable to the path specified under "JDK location".


回答4:

I'm gonna go on a long shot here. There is a tools.jar in java libs folder.[the java sdk that is]

Usually all these frameworks and ides have a lib folder themselves. and it is missing said tools.jar. Just copy paste it there.



回答5:

I had the same problem while running react-native run-android it gave me the error tool.jar not found. i solved this by adding a single line mentioned below, in gradle.properties file which is in android project. org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_121



回答6:

If this problem occurs for Windows, then the solution here is fairly simple.

Install Chocolatey

  • Follow the installation instructions on this page. https://chocolatey.org/install

Install jdk8

Restart Command Prompt or Powershell as Administrator, and run:

choco install jdk8

Now if you run

react-native run-android

This error shouldn't show up.



回答7:

Find and copy tool.jar from JDK path C:\Program Files\Java\jdk1.8.0_151\lib\tool.jar

then paste it in JRE folder C:\Program Files\Java\jre1.8.0_181\lib

then delete build folder from your project/android/app/=>build

and then try react-native run-android



回答8:

Just to add another data point for people pulling their hair out. I think a java update may have messed up my environment that was working fine 2 months ago. The combination of what worked for me:

Set JAVA_HOME to 1.7, NOT 1.8.

I had 2 1.8 versions installed and neither worked.



回答9:

I know this question is for Windows, but this is the first result for this error on Google, so for Linux this problem could be fixed with:

sudo apt install default-jdk



回答10:

I have deleted "\react_native_project_path\android" directory and run

    reactive-native android

then run ..

    reactive-native run-android

Then the error is gone