I went to Android Studio > Preferences > Build, Execution, Deployment > Build Tools > Gradle. Under Gradle JDK, I found that JetBrains Runtime (JDK 21) was selected by default. I changed this to Homebrew OpenJDK 17 (or any compatible JDK 17 installation) from the dropdown.
My Android Studio, Gradle plugin everything is up to date and latest.