简体   繁体   English

Android Studio的构建时间过长

[英]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. Android Studio花费太长时间来构建gradle,刷新应用程序文件等。我试图以离线模式运行它。 Then the gradle sync is getting failed. 然后gradle同步失败。 I don't want to use the Internet connection for running applications in Android Studio. 我不想使用Internet连接在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. Android Studio速度缓慢是因为文件索引编制和gradle构建,而不是因为在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. 如果您没有用于在其中存储项目的SSD,则构建过程可能需要几分钟。 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. 如果您有足够的RAM(8GB +),则可以创建一个较小的RAM磁盘分区,然后在其上移动项目。 Be sure to leave a few hundred MB free on it for gradle to use. 请确保在其上留出几百MB的可用空间以供gradle使用。 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. 您可以使用这些工具之一来创建RAM磁盘,最近两年来我一直在使用ImDisk,并且它运行良好,现在在设备上安装apk所需的时间比构建应用程序所需的时间更长。 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. 最好将gradle缓存(通常存储在主目录中的.gradle文件夹)也放在RAM磁盘上,以加快构建速度,但这影响较小。 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. RAM是易失性的(在关闭电源时会擦除),因此请务必在关闭电源之前始终将RAM磁盘内容复制到永久性存储中。 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. 如果您在经常停电的地方,而不是使用电池电量充足的笔记本电脑,请购买UPS,否则将丢失RAM磁盘内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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