用了1个多月的AS了,感觉比eclipse好的不是一点半点,但是就是有一点,编译一次太慢了,最长要接近6分钟,感觉真的是无法忍受了,所以放下手头上的事,找了一些资料,下面说一下。
1.在android studio的配置中,开启offline模式,
原因:offline work,看名字就知道是离线工作,因为gradle每次启动都会有联网检测依赖的各种文件是否是最新版本,导致每次都相当慢。如果确定了你的工程中的jar包或者依赖工程都齐全,也不想去更新最新的,就可以在gradle setting中勾选offline,这样就不会去更新了。
2.配置相关
3.修改项目下的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)org.gradle.daemon=true 开启gradle单独的守护进程
(2)org.gradle.configureondemand=true
(3)org.gradle.parallel=true 让gradle可以平行的运行
(4)org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 增大gradle运行的java虚拟机的大小
优化完这些测试:Rebuild project,时间从接近6分钟变为了58s,改善还是相当可观的。