I spent almost 2 hours to debug this when I was using react/capacitor application. Anyone on Mac, this will help :)
🔧 How to Fix the Java Version in Android Studio
Open Android Studio
- Open your project in Android Studio.
Go to Gradle Settings
- Click on File → Settings (on Mac, it's Android Studio → Settings).
- Navigate to:
Build, Execution, Deployment → Gradle
Change the "Gradle JVM"
- Look for the option "Gradle JVM"
- Click the dropdown and select Java 17
- If Java 17 is not available, click "Download SDK", then select Java 21 (Eclipse Temurin is a good choice).
Apply & Restart
- Click Apply and OK
- Restart Android Studio
Now, Gradle will use Java 17 instead of Java 21, and your build should work without errors. 🚀