如何加速Android Studio 2.3或3?

Raj*_*ena 6 android gradle android-studio

我的系统有8 GB RAM,i5 Haswell Processor,2GB Nvidia Graphics card512 GB HDD,还是我的系统是无法处理Android Studio(稳定和金丝雀版本).

它令人沮丧地缓慢并挂起整个系统.这应该是那样的吗?我是否需要更强大的系统来开发Android应用程序?它会影响生产力,我正在考虑完全放弃Android开发,因为浪费的时间和处理的挫败感Gradle.

有没有什么方法可以开发Android应用程序而不会感到沮丧,每一次?

编辑 有一个类似的问题 Android Studio很慢(如何加速)?,但我要问的是更新版本的Android Studio,谷歌声称(他们每年都说这些)已经制作significant enhancements了构建和任何流程.

更新2018年5月1日 我将系统升级到250 GB SSD,现在Android Studio似乎加载了一个数量级.

小智 6

用户回答:https://stackoverflow.com/users/624706/sergii-pechenizkyi

来源:通过Gradle和Android Studio构建和运行应用程序比通过Eclipse慢

硬件

对不起,但是将开发站升级到SSD和大量的ram可能比以下几点的影响更大.

工具版本

提高构建性能是开发团队的首要任务,因此请确保您使用的是最新的GradleAndroid Gradle插件.

配置文件

创建一个gradle.properties在任何目录中命名的文件:

  • /home/<username>/.gradle/ (Linux)的
  • /Users/<username>/.gradle/ (苹果电脑)
  • C:\Users\<username>\.gradle (视窗)

附加:

# 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.
# https://medium.com/google-developers/faster-android-studio-builds-with-dex-in-process-5988ed8aa37e#.krd1mm27v
org.gradle.jvmargs=-Xmx5120m -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

# Set to true or false to enable or disable the build cache. 
# If this parameter is not set, the build cache is disabled by default.
# http://tools.android.com/tech-docs/build-cache
android.enableBuildCache=true
Run Code Online (Sandbox Code Playgroud)

如果放置它们,Gradle属性在本地工作,如果放置它们,则Gradle属性在projectRoot\gradle.properties全局工作user_home\.gradle\gradle.properties.如果从控制台或直接从构思运行gradle任务,则应用属性:

IDE设置

可以从IDE设置GUI调整Gradle-IntelliJ集成.启用"离线工作"(检查从答案Yava公司下文)将禁止在每一个"的gradle同步文件"真正的网络请求.

IDE设置

原生多语言

apk构建的最慢步骤之一是将java字节码转换为单个dex文件.启用本机multidex(仅适用于调试版本的minSdk 21)将有助于工具减少工作量(请参阅下面的Aksel Willgert的答案).

依赖

更喜欢@aar库子项目的依赖关系.

mavenCentral,jCenter上搜索aar包或使用jitpack.io从github构建任何库.如果您不编辑依赖项库的源代码,则不应每次使用项目源构建它.

杀毒软件

考虑从防病毒扫描中排除项目和缓存文件.这显然是与安全的权衡(不要在家里试试!).但是如果你在分支机构之间切换很多,那么防病毒软件会在允许gradle进程使用它之前重新扫描文件,这会减慢构建时间(特别是带有gradle文件和索引任务的AndroidStudio同步项目).测量构建时间并在启用和未启用防病毒的情况下处理CPU,以查看它是否相关.

分析构建

Gradle内置了对概要分析项目的支持.不同的项目使用插件和自定义脚本的不同组合.使用--profile将有助于找到瓶颈.