in my case, in macOS and for flutter:
in zshrc or bash, save this:
export JAVA_HOME=<yourJdkPath>
in terminal, set this:
flutter config --jdk-dir="${JAVA_HOME}"
without flutter config command, and only setting java home, I even could not run counter app, as expected. Applying both solved my problem.