android studio運作編譯速度慢的解決方法
轉載:https://www.gezila.com/tutorials/58146.html
轉載:http://blog.csdn.net/chenliguan/article/details/47605851
最近開始安裝使用android studio,痛苦的發現安裝或者後期更新後as運作時非常的卡。于是,深入的研究解決方法并不斷的嘗試,最後總結出如下的兩點。
一、工具軟體配置
1、解決網絡連接配接問題
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM3EDN0gDM5AzMxgDM1EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
(1)問題描述
檢查你的 Android SDK,卡上很長時間,需要更新則需要進行安裝。
(2)方法步驟
①跳過這一步,可在Android Studio安裝目錄下的 bin 目錄下,找到 idea.properties 檔案,在檔案最後追加disable.android.first.run=true 。
②或者:使用牆外代理。
2、解決記憶體吃緊問題
(1)問題描述
Android Studio 安裝目錄的-xmx 參數是 Java 虛拟機啟動時的參數,用于限制最大堆記憶體。Android Studio 啟動時設定了這個參數,并且預設值很小。 一旦你的工程變大,IDE 運作時間稍長,記憶體就開始吃緊,頻繁觸發 GC,自然會卡。
(2)方法步驟
每次更新/安裝 Android Studio 之後都修改android-studio/bin/studio.vmoptions studio64.vmoptions 兩個檔案的以下屬性:
-Xms2048m
-Xmx2048m
-XX:MaxPermSize=2048m
-XX:ReservedCodeCacheSize=2048m
3、解決建構速度慢問題
(1)問題描述
随着項目的增大,依賴庫的增多,建構速度越來越慢,現在最慢要6分鐘才能build一個release的安裝包
(2)方法
開啟gradle單獨的守護程序,增大gradle運作的java虛拟機的大小,讓gradle在編譯的時候使用獨立程序,讓gradle可以平行的運作。
(2)步驟
①在下面的目錄下面建立gradle.properties檔案:C:\Users\.gradle (Windows)
②在檔案中增加:org.gradle.daemon=true
③優化以上使用者目錄下的gradle.properties檔案,配置如下:
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
# TODO: disable daemon on CI, since builds should be clean and reliable on servers
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
二、更新硬體
雖然對工具進行配置,但是需要更佳的使用者體驗,還是需要更新硬體。推薦更新配置為:I5+8G和128GSSD,甚至更高。
總結,經過如上的配置和更新,AS的運作速度明顯提升,開啟軟體隻需4-6s,Gradle隻需4-6s。