Android Studio is taking too long time to build gradle, refresh application files etc. I have tried to run it in offline mode. Then the gradle sync is getting failed. I don't want to use the Internet connection for running applications in Android Studio.
-
have you tried: https://stackoverflow.com/questions/29391421/android-studio-gradle-takes-too-long-to-build – Darush Sep 30 '17 at 05:27
-
Internet connection is not required to run your applications. Only that each dependency you add to gradle files need some "extra code", which they fetch through the internet. That is why `sync` fails in offline mode. Because `sync` tries to fetch fix all the dependecies and align them. – zeekhuge Sep 30 '17 at 05:28
1 Answers
Android Studio is slow because of the file indexing and gradle build, not because of the network which it uses mostly after you add new dependencies in your gradle.build. It transfers a lot of data to & from disk for every build and slows down the whole machine.
If you don't have an SSD to store your project on it, the build can take minutes. You should enable the instant run option which will significantly reduce build time for small changes. If you have plenty of RAM (8GB+) you could create a small RAM disk partition and move your project on it. Be sure to leave a few hundred MB free on it for gradle to use. You can use one of these tools to create the RAM disk, I have been using ImDisk at work for the last couple of years and it works perfectly, it now takes longer to install the apk on the device than to build the app. Preferably the gradle cache should (the .gradle folder usually stored in your home directory) also be on the RAM disk for quickest builds, but this has a smaller impact. If you want to move the cache, create a file system link to it in the initial location.
CAUTION. RAM is volatile (erased when power is off), so be sure to always copy your RAM disk content to persistent storage before powering off. If you are in an area with frequent blackouts and not using a laptop with good battery, get an UPS or you will lose the RAM disk content.

- 1,102
- 7
- 13