Problem Debugging and Running Code

I’m kinda new to Android development.

However, I always tend to stop at the same point, “Trying to debug and run code”

I would like to run my first flutter project on my phone via Android Studio but there seems to be an issue with gradle that I do not understand.
I’m getting the following error message;

Launching lib\main.dart on TECNO B1p in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe

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

Please help me out. I don’t want to give up again on first time.


Go to the Gradle settings in Android Studio and make sure a proper JDK is selected to run Gradle.
It seems it tries to use some built-in Java that is not compatible or something like that.

Where do I locate that please? I downloaded JDK, also downloaded the Android Studio suggestion (Android API 34 Platform) but still it’s like something is missing.

Where do I locate the settings for selecting the JDK, please?

On the Gradle settings page. Just type Gradle into the search box of the settings dialog. And better use a JDK that is compatible with the Gradle version your are using: Compatibility Matrix

Saw a search button, used it to try and find gradle, but it just throws me a bunch of code as below:

include ‘:app’

def localPropertiesFile = new File(rootProject.projectDir, “”)
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader(“UTF-8”) { reader → properties.load(reader) }

def flutterSdkPath = properties.getProperty(“flutter.sdk”)
assert flutterSdkPath != null, “flutter.sdk not set in”
apply from: “$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle”

It is in IntelliJ, but AS is a customized IJ so should be almost the same.