So the problem arises from inconsistency in the Java version installed on your machine, the default Java version configured on your android studio and the gradle version for your project.
So building upon the answer given by Tafita Raza I fixed it following the steps below
- Check your java version and remember it, use "java -version" in terminal
- Go to your android studio path installation
- In newer versions of android studio go to Andriod Studio/jbe while in older versions go to Android Studio/jre/ and edit the file named "release"
- Replace the value of JAVA_VERSION with the version of Java installed on your machine if it's not the same as the java version on your computer
- Now go into the project folder you are building and check if the gradle version is compatible with the Java you have installed
[![Java and gradle compatibility][1]][1]
- I had java 19.0.2 installed on my system so according to the table I need gradle version 7.6 to build a project. You can also check the official website gradle if your java version is not listed
[To see links please register here]
- Go into your project_name/android/gradle/wrapper and edit the file gradle-wrapper.properties
- Replace the distributionUrl with the version of gradle compatible with the java version on your system
[![DistributionUrl Example][2]][2]
[1]:
[2]: