您好,欢迎来到爱go旅游网。
搜索
您的当前位置:首页提高Android Studio/Gradle编译速度的配置

提高Android Studio/Gradle编译速度的配置

来源:爱go旅游网

我们在使用Android Studio开发的时候都会有这样的一种经历:“随着项目的增大,项目编译的速度会越来越慢!”。尤其在我刚开始开发的时候,不注重项目大小的优化,导致项目越来越庞大,编译时间越来越久。今天就专门在网上找了些关于Android Studio提升编译速度的相关知识,并总结一下。(亲测有效哦)

加速一:开启gradle单独的守护进程



在下面的目录下面创建gradle.properties文件:
      • /home/<username>/.gradle/ (Linux)
      • /Users/<username>/.gradle/ (Mac)
      • C:\Users\<username>\.gradle (Windows)

在文件中添加:

另外修改项目中的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

</span>

上面的配置文件主要功能:增大gradle运行的java虚拟机的大小,让gradle在编译的时候使用进程,让gradle可以并发的运行。


加速二:配置Android Studio

在Android Studio 的配置中,开启offline模式,以及修改配置。这些配置主要和开启gradle的线程效果相仿,主要是在这个地方配置的只会在IDE构建的时候生效,命令行构建不生效。




加速三:命令行构建

基于上面的配置,命令行构建时在命令后面加上这个参数即可  --daemon --parallel --offline

加速四:引入依赖库是使用aar

使用网上第三方的依赖库时尽量使用aar,可以在 搜索

自己的库模块也可以打包成aar,相关知识参考:


后记

配置之后,构建速度至少提升一倍,速度那是杠杠的!




因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务