Cause
While Android Studio build process is in action, it create a lot of intermediate files in order to compile and package source code and resources. Enabling real time scanning in antivirus softwares will force it to scan all these newly created files for vulnerabilities. This is may interfere with the Android Studio build process, causing builds to run dramatically slower.
Fix
Exclude real-time scanning on these directories.
Gradle cache
%USERPROFILE%\.gradle
Android Studio projects
%USERPROFILE%\AndroidStudioProjects
Android SDK
%USERPROFILE%\AppData\Local\Android\SDK
Android Studio system files
C:\Program Files\Android\Android Studio\system
This is how you can accomplish the same in different antivirus softwares.
Windows Defender
Kaspersky
AVG Antivirus
Note: You can also disable the disable real-time scanning completely. This method isn't recommenced since it will open security risks.