On triggering Clean–>Rebuild in Android studio, the gradle build system downloads the latest Jar or Lib files from internet, downloading these files based on internet speed. If you enable below options, the gradle reuse the cached jar or lib always & works offline.
Update: Simply upgrade to SSD for faster performance, here my new post about how i made my Android studio work faster.
Go to File –> Settings –> search for Gradle –> Offline work [check this box].
Now go to service directory path, it will be C:\Users\[yourname]\.gradle folder. create file named `gradle.properties` & add `org.gradle.daemon=true`
Now, restart your Android studio & build the application, observe the changes.
Note: If you add new dependency in Gradle file, then you must connect to internet to make it work. Afterwards, you can use the cached data to build your applications.
Even after doing this also, you may face slowness in Android studio. This problem occurs because of slow read/write speed of Hard disk, Gradle build system architecture is very different, to improve the write speed update hardware from HDD to SSD (solid state disk). The write & read speed of solid state hard disk is 10 to 15 times faster then normal Hard disk.
For Android studio, Google recommends you to have 2 to 4GB of RAM and 1GB of hard disk space of emulator images, SDK etc.. For better speed update to solid state drive.
Above task manager image is taken during the build time, CPU consumption is just 7%, RAM is 51% i.e out of 4GB only 2GB of RAM is getting utilized. But Memory consumption is 100%, write speed is just 12 KB/s and Read speed is 7.2 MB/s.
This clearly indicates, improving the read and write speed will surely improve the build speed of the Android studio for this update to SSD.
Most of the Apple laptops comes with SSD, so there wont be any issues,but this is not the case for Windows PC.