天天看点

android studio用起来很卡,解决方法

android studio运行编译速度慢的解决方法

转载:https://www.gezila.com/tutorials/58146.html

转载:http://blog.csdn.net/chenliguan/article/details/47605851

最近开始安装使用android studio,痛苦的发现安装或者后期升级后as运行时非常的卡。于是,深入的研究解决方法并不断的尝试,最后总结出如下的两点。

一、工具软件配置 

1、解决网络连接问题

android studio用起来很卡,解决方法

(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。