I got this issue because of older android studio version. You need to install latest new version of android studio which supports 17 jdk version.
For this error to go , launch Android Studio and Click on Help > About and take a note of the Runtime. For me, it was a JDK version 11 so
After updating to chipmunk version i.e 2023.3.1 the same About page showed JDK 17 and the Android builds ran fine.
You can try this. If it solves dont forget to upvote