加速Android Studio---Gradle构建

来源:互联网 发布:java仿qq好友列表 编辑:程序博客网 时间:2024/06/01 07:30

1、对整个开启gradle单独的守护进程(所有项目生效)
在下面的目录下面创建gradle.properties文件:

/home//.gradle/ (Linux)
/Users//.gradle/ (Mac)
C:\Users\.gradle (Windows)

并在文件中增加:

org.gradle.daemon=true 

2、修改项目下的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  

以上三个配置选项分别是:
增大gradle运行的java虚拟机的大小,
让gradle在编译的时候使用独立进程,
让gradle可以平行的运行。

3、开启offline模式

这里写图片描述

在这个地方配置的只会在ide构建的时候生效,命令行构建不会生效。

4、命令行构建

如果你使用的是命令行构建,Command Line Options加上上述参数。

这里写图片描述

参数用法详情请参考官方文档:
https://docs.gradle.org/current/userguide/gradle_command_line.html

5、引入依赖库时使用aar
使用网上第三方的依赖库时尽量使用aar,可以去maven,github搜索。
自己的库模块也可以打包成aar,关于这个可以参考stormzhang的文章http://www.stormzhang.com/android/2015/03/01/android-reference-local-aar/。

0 0
原创粉丝点击