I can't build a flutter app

Hi!

I have tried multiple times to run the default flutter app (which you get when you first create a new flutter app, so it doesn’t contain errors for sure) and I can’t do that successfully.

That’s what I get:

Running "flutter pub get" in first_app...                           4,1s
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:compileDebugKotlin'.
> Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files (x86)\Java\jre1.8.0_251' used by Gradle. Make sure Gradle is running on a JDK, not JRE.

* 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 1m 11s
Exception: Gradle task assembleDebug failed with exit code 1

There’s not really more that can be said beyond the error message…

> Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files (x86)\Java\jre1.8.0_251' used by Gradle. Make sure Gradle is running on a JDK, not JRE.

You need a JDK, not a JRE and your Java install at C:\Program Files (x86)\Java\jre1.8.0_251 is most definitely a JRE.

But how do I tell Gradle to use JDK instead of JRE?

Is it related to the environment variables that I set?

Ok, I’ve solved the issue by adding JAVA_HOME to user variables and the path to the system variables following this guide more or less: https://dev.to/ejgamer21/install-flutter-without-android-studio-58bi