加快android studio 编译速度
工程build一次太慢 经过各种搜索 整合以下 仅供参考
1、在下列目录中新建 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
同样也可以将global properties 设置如上 所以的工程都会依照这个设置
3、打开file-setting-build-compiler进行如下设置
打开file-setting-build-buildTool进行如下设置
此处设置为offline 并且 应用本地gradle 加快编译速度
4、打开file-Project Structure
设置gradle的version
5、在你的app gradle下 添加如下
dexOptions {
incremental true
javaMaxHeapSize "4g"
preDexLibraries = false
}
6、除此之外 由于国内访问国外服务器较慢 造成as又卡又慢
所以尽量使用jar arr 等方式 减少直接compile
*.jar:只包含了class文件与清单文件,不包含资源文件,如图片等所有res中的文件。
*.aar:包含所有资源,class以及res资源文件全部包含
如果你只是一个简单的类库那么使用生成的*.jar文件即可;
如果你的是一个UI库,包含一些自己写的控件布局文件以及字体等资源文件那么就只能使用*.aar文件。