flutterandroid-emulatorjava-homeavd-manager

JAVA_HOME error when running Flutter code with Android Emulator


I am setting Flutter for the first time and I keep getting this error when trying to run the Flutter code on a Pixel 2 emulator:

Launching lib\main.dart on AOSP on IA Emulator in debug mode... ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-16.0.1\jdk-16.0.1 Please set the JAVA_HOME variable in your environment to match the location of your Java installation. Exception: Gradle task assembleDebug failed with exit code 1 Exited (sigterm)

I tried deleting and reinstalling Android Studio and Java SDK, but it does not solve anything.

I tried setting the JAVA_HOME variable in environmental variables with the following path: C:\Program Files\Java\jdk-16.0.1\jdk-16.0.1 ...but nothing, same error.

Thanks for your help

Important Notice: My android sdk is installed on the D partition, while the Java sdk is on the C drive. Does it matter ?


Solution

  • Open powershell and write java --version

    If you dont get the version try to add again the Java_home to path

    Nevertheless, I think java home should be on C:\Program Files\Java\jdk-16.0.1\jdk-16.0.1\bin directory