1

I am on Mac.

Output of echo $JAVA_HOME:

/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home

Output of Visual Studio when I try to build my Flutter app for Android:

Launching lib/main.dart on sdk gphone x86 arm in debug mode...
lib/main.dart:1
ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/bin/
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)
Joel Castro
  • 485
  • 6
  • 20

1 Answers1

0
// open terminal on mac

// install homebrew if not installed

run  > /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

// install java

run > brew install openjdk

nano ~/.zshrc

press key > ctrl + O 

paste (location path) > export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

press > return

press key > ctrl + X

// close terminal 

// try to build flutter app (.apk) 

 
Dipak K
  • 96
  • 2