加快AndroidStudio编译速度

来源:互联网 发布:如何开好淘宝网店 编辑:程序博客网 时间:2024/05/14 11:05

一、创建配置文件


打开C:\Users\用户名.gradle

新建一个gradle.properties文件,并在里面添加以下内容,也可以直接写在用户目录下的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 serversorg.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=256morg.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_projectsorg.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_demandorg.gradle.configureondemand=true

上面的配置文件主要就是做, 增大gradle运行的java虚拟机的大小,让gradle在编译的时候使用独立进程,让gradle可以平行的运行。

二、配置Android Studio的Gradle

在android studio的配置中,开启offline模式,以及修改配置。实际上的配置和上面的一大段一样,主要是在这个地方配置的只会在ide构建的时候生效,命令行构建不会生效。 





三、配置当前项目core下build.gradle

添加dex增量编译 
这还是一个实验性的功能,但是还是推荐打开试试,设置dexOptions

dexOptions {    //使用增量模式构建    incremental true    //最大堆内存    javaMaxHeapSize "8g"    //是否支持大工程模式    jumboMode = true    //预编译    preDexLibraries = true    //线程数    threadCount = 8}




原创粉丝点击