I tried the below commands, which are for clearing local/global caches for android and gradle, which worked for me and I think would work for everyone having the same issue/error while building the react native android app :-
Remove and Reinstall Android Build Files :-
Clear Gradle Cache Manually :-
If the above steps don't work, manually delete the Gradle cache:- Linux:
Command Prompt:
Delete node_modules :-
rm -rf node_modules
Clear Yarn Cache:-
yarn cache clean
Install npm packages :-
yarn OR npm install
Start the server and run android with the commands used.