如何加快 Android Studio 编译过程 [英] How to speed up Android Studio compilation process

查看:24
本文介绍了如何加快 Android Studio 编译过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最新更新:查看 Android Studio 2.0(预览版)Instant Run,太棒了!!!

Latest update: Check out Android Studio 2.0 (preview) Instant Run it is awesome!!!!

我发现了一些提示(通过 Gradle 和 Android Studio 构建和运行应用程序比通过 Eclipse 慢) 以加快 Android Studio (Gradle) 的编译过程,但我仍然认为它太慢了.编译项目并在设备上运行大约需要15秒.

I have found some tips (Building and running app via Gradle and Android Studio is slower than via Eclipse) to speed up the compilation process of Android Studio (Gradle) but I still think it is way too slow. It takes about 15 seconds to compile the project and run on the device.

gradle.properties 已经设置为:

The gradle.properties is already set to:

org.gradle.daemon=true

org.gradle.daemon=true

org.gradle.parallel=true

org.gradle.parallel=true

惊人的!!!我的同事报告说杰克和吉尔可能是解决方案:http://www.infoworld.com/article/2856113/mobile-technology/androids-new-jack-and-jill-compilers-head-uphill-to-developers.html 我正在阅读.

Awesome!!! Colleague of me reported that Jack and Jill might be the solution: http://www.infoworld.com/article/2856113/mobile-technology/androids-new-jack-and-jill-compilers-head-uphill-to-developers.html I'm reading into it.

看看这个解释:https://www.saikoa.com/blog/the_upcoming_jack_and_jill_compilers_in_android

编辑 2:关于杰克和吉尔的新信息!:http://tools.android.com/tech-docs/jackandjill

Edit 2: New info on Jack and Jill!: http://tools.android.com/tech-docs/jackandjill

编辑 3:Android Studio 2.0 似乎让我们摆脱了所有的负担!查看即时运行".http://android-developers.blogspot.nl/2015/11/android-studio-20-preview.html

Edit 3: Android Studio 2.0 seems to release us from all the burden! Check out "Instant Run". http://android-developers.blogspot.nl/2015/11/android-studio-20-preview.html

推荐答案

配置构建以减少构建时间有两个主要任务.

There are two main tasks to configure your build to reduce the build time.

首先,您必须使用特殊标志配置您的编译以使其更快.编辑您的 gradle.propertieslocal.properties 文件,如下所示:

First, you have to configure your compilation with special flags to make it faster. Edit your gradle.properties or local.properties files as follow:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
android.enableBuildCache=true

说明:

  • Android Studio 2.2 dexing-in-process 中包含的新选项至少需要 3GB 内存.如果您的计算机没有足够的内存,您可以将此属性调整为更适合您的设置的内容.
  • 构建缓存是 Android Studio 2.2 中引入的一项新功能,可大大改进构建.更多信息在这里http://tools.android.com/tech-docs/build-cache .在 Android Studio 2.3 或更高版本中默认为 true
  • At least 3gb of memory are required by the new option included in Android Studio 2.2 dexing-in-process. If your computer doesn't have enough memory you can adjust this attribute to something more appropriate for your setup.
  • Build Cache is a new feature introduced in Android Studio 2.2 that improve a lot the builds. More info here http://tools.android.com/tech-docs/build-cache . In Android Studio 2.3 or superior is true by default

使用这种配置,构建时间通常从 2-3 分钟减少到 30 秒或更短.最重要的部分是 configureondemand 属性.更多信息这里配置Android Studio参数

With this configuration, build time is often reduced from 2-3 minutes to 30 seconds or less. The most important part is the configureondemand attribute. More info here to configure Android Studio parameters

首先,使用 minSDKVersion >= 21* 编译您的项目.如果您的应用具有较低的最低 SDK 版本,您可以创建一个特殊的 productFlavour 用于开发目的,如下所示:

First, one is compiling your project with a minSDKVersion >= 21*. If your app has lower min SDK version you can create a special productFlavour for development purposes as follow:

productFlavors {

    production {
        minSdkVersion 15
        ...
    }

    development {
        minSdkVersion 21
        ...
    }
}

*重要的是,在 Android Studio 2.4 中不再需要此操作,因为 IDE 会自动进行此操作.

这篇关于如何加快 Android Studio 编译过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆