0

Launching lib\main.dart on Android SDK built for x86 in debug mode... Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_271 contains a valid JDK installation.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 4s Exception: Gradle task assembleDebug failed with exit code 1

This is the full code i get in my debugger. I have tried to remove and reinstall java once also added the environment variable JAVA_HOME properly still this issue is not leaving me from last 2 days . Getting frustrated due to it. Please Help

Thor Xd
  • 1
  • 1
  • I just noticed that the error says that your *JRE* directory must contain a valid *JDK* installation... I also noticed in my JDK installation that the `tools.jar` file exists under `lib` subdirectory and that no `tools.jar` exists inside the JRE (which, the JRE itself, is located in a corresponding subdirectory of the JDK). And, as far as I know, you should be building against the JDK, and not the JRE. – gthanop Jan 13 '21 at 18:08
  • sir but i have installed jdk also i cant find tools.jar anywhere under lib subdirectory what should i do then – Thor Xd Jan 14 '21 at 04:02

1 Answers1

0

Judging from the error you are seeing seems like Gradle is set to point at your JRE standalone installation and not the JDK...

Judging also from your post, seems like you are running Windows.

So, first of, make sure you have the JDK installed:

  1. You can search for it in your file system yourself (which is most likely located under
    C:\Program Files\Java\ directory).
  2. Open a CLI (ie Command Line Interface, or command prompt) and type javac -version and tell us how it responds.
  3. Open a CLI and type where javac and tell us how it responds. It should print the location of your javac.exe executable (which will be under the JDK install directory, which in turn will let us know where is your JDK installed).

If you don't have the JDK installed, make sure you do, by downloading+installing it. For example you can get Oracle's JDKs from here. Make sure you select the desired JDK and not JRE. For example for version 8 (which is the version of Java I can see you are using) you can navigate here.

Then, make sure Gradle points to the JDK installation and not the standalone JRE.

To do this, I am not an expert on it, but if Gradle is using JAVA_HOME enviroment variable, make sure this value points to your JDK and not the JRE. You can open a CLI and type
echo %JAVA_HOME% and tell us how it responds. If it shows a JRE installation, try changing this enviroment variable to the JDK installation. Also don't forget to put %JAVA_HOME%\bin in your PATH enviroment variable if it is not already (more on this later in this post).

By the way, which IDE are you using (for example Android Studio, Eclipse, etc...)?

Aside from everything I am suggesting you here to tell us, you can try the following answers in another similar post which may help:

  1. How to configure Gradle to run from JDK.
  2. How to set JAVA_HOME properly to point to the JDK.
  3. How to override default java.home Gradle property.

Note that JAVA_HOME is an enviroment variable which should point to the JDK, while the java.home is a Gradle property which should point to the JRE.

Try the possible solutions above, and don't forget to let us know your observations and how each CLI command responds.

gthanop
  • 3,035
  • 2
  • 10
  • 27