Hey What happens if you do echo $JAVA_HOME in your zsh shell,
And in android studio you could go to Preferences > Build, Execution, Deployment > Build Tools > Gradle, There should be a Gradle JDK option try Changing it to JDK 17.
Please make sure that zsh is your default shell.
May this guide help you if the above does not work, https://www.devgem.io/posts/resolving-flutter-s-java-home-error-on-macos-step-by-step-guide