M1 JDK issue in Building Expo project

Hi there, I'm Joy I'm a full stack developer, mobile application developer, Cyber security analyst, SEO analyst, trainer. Check my latest updates in www.joysam.me
This problem arises from an incompatibility between the JDK and Gradle, specifically in the context of the M1 architecture. Despite the absence of a comprehensive solution available in the online, I have taken the initiative to provide a resolution based on my findings and insights. This solution method uses JDK of Android studio to build instead of M1 Mac's Termurin JDK.
The ZSH command
npx expo prebuild && npx expo run:android --device
The error:
✔ Select a device/emulator › Pixel_3a_API_TiramisuPrivacySandbox (emulator)
› Using --device Pixel_3a_API_TiramisuPrivacySandbox
› Building app...
Configuration on demand is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings generic class cache for settings file '/Users/joy/Dev/Projects/Kallardo/mobile/android/settings.gradle' (/Users/joy/.gradle/caches/7.5.1/scripts/9kz1kv2g6929u11lqmx2zd9z3).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 64
Let's jump into a Quick solution:
Open Android studio-> File-> Project Structure-> SDKs

Copy the JDK home path, i.e the path Android studio default JDK
Open terminal
nano ~/.zprofile
or
subl ~/.zprofile
Add the following code in the ~/.zprofile
export JAVA_HOME="The value we copied"
Close all terminals using the dock!
Open the terminal again and run your code again (in my case expo prebuild && npx expo run:android --device) it might work :)
If the problem still exists follow the Clearing Cache steps and run again
Clearing the Cache of expo
Deleting cache of global Gradle
rm -rf $HOME/.gradle/caches/Deleting Cache of project Gradle
cd project_dir/android && ./gradlew cleanCheck the JVM and other configs using
./gradlew --version




