简体   繁体   中英

Android Studio taking too long time to build

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM