使用 Gradle (Android Studio) 进行极长的构建 [英] Extremely long build with Gradle (Android Studio)

查看:26
本文介绍了使用 Gradle (Android Studio) 进行极长的构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,对于非常简单的更改,我们的构建时间为 2 分 30 秒.这(与 ANT 相比)非常缓慢并且正在扼杀整个团队的生产力.我正在使用 Android Studio 并使用使用本地 gradle 发行版".我试图给 gradle 更多的内存:

<块引用>

org.gradle.jvmargs=-Xmx6096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

更多的内存.并且它仍然不时为内存提供错误.

<块引用>

线程pool-1-thread-1"中的异常java.lang.OutOfMemoryError:超出GC开销限制

了不起.我正在使用并行选项和守护进程:

<块引用>

org.gradle.parallel=true

org.gradle.daemon=true

这并没有真正的帮助.

我已经将上述参数放在 ~/.gradle/gradle.properties 中(我什至怀疑 Android studio 是否忽略了它,所以我进行了测试 - 它没有忽略它).

仍然从终端我得到 1:30 的构建时间与 Android Studio 中的 2:30,所以不确定那里出了什么问题.与 Ant 相比,1:30 仍然很疯狂.如果您知道 Android Studio 正在做什么(或忽略或重写为 gradle 配置),我将不胜感激.

所以只要 CMD + B(简单编译)在更改后超级快,比如 7 秒.但是当涉及到运行应用程序时,它启动了 dexXxxDebug 任务,这简直要了我们的命.我试过把

<块引用>

dexOptions {preDexLibraries = false}

没有帮助.

我知道 gradle 可能还没有为生产环境做好准备,但我开始后悔我们这么早决定迁移到它.我们有很多模块,这可能是问题的一部分,但这不是 Ant 的问题.

感谢任何帮助,丹

有关执行时间的更多信息:

描述持续时间

总构建时间 1m36.57s启动 0.544s设置和 BuildSrc 0.026s加载项目 0.027s配置项目 0.889s任务执行 1m36.70s

时间食客::app:dexDebug 1m16.46s

解决方案

我不太确定为什么 Android Studio 比命令行慢,但是您可以通过打开增量 dexing 来加快构建速度.在您模块的构建文件中,将此选项添加到您的 android 块:

dexOptions {增量真}

在那个 dexOptions 块中,您还可以指定 dex 进程的堆大小,例如:

dexOptions {增量真javaMaxHeapSize "4g"}

这些选项取自 adt-dev 邮件列表 (https://groups.google.com/forum/#!topic/adt-dev/r4p-sBLl7DQ) 有更多的上下文.

right now we are in a situation of having build times 2 minutes 30 seconds for very simple change. This (compared to ANT) is amazingly slow and is killing the productivity of the whole team. I am using Android Studio and using the "Use local gradle distribution". I've tried to give more memory to gradle:

org.gradle.jvmargs=-Xmx6096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

A lot more memory. AND IT IS STILL GIVING ERRORS FOR MEMORY from time to time.

Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: GC overhead limit exceeded

Amazing. I am using the parallel option and daemon:

org.gradle.parallel=true

org.gradle.daemon=true

It doesn't really help.

I've put the aforementioned parameters in ~/.gradle/gradle.properties (and I even doubted that Android studio is ignoring that, so I tested - it is not ignoring it).

Still from terminal I get 1:30 build time vs 2:30 in Android Studio, so not sure what is wrong there. 1:30 is STILL CRAZY compared to Ant. If you know what Android Studio is doing (or ignoring, or rewriting as gradle config), I'd be grateful to know.

So just CMD + B (simple compile) is super fast after changes, like 7 seconds. But when it comes to running the app, it starts the task dexXxxDebug, which is just killing us. I've tried putting

dexOptions {
    preDexLibraries = false
}

Doesn't help.

I understand that gradle is probably still not ready for production environments, but I'm starting to regret our decision to move so early to it. We have lots of modules, which is probably part of the problem, but that was not an issue with Ant.

Any help appreciated, Dan

Some more information about execution times:

Description Duration

Total Build Time    1m36.57s
Startup 0.544s
Settings and BuildSrc   0.026s
Loading Projects    0.027s
Configuring Projects    0.889s
Task Execution  1m36.70s

The time eater: :app:dexDebug 1m16.46s

解决方案

I'm not quite sure why Android Studio is slower than the command line, but you can speed up your builds by turning on incremental dexing. In your module's build file, add this option to your android block:

dexOptions {
    incremental true
}

In that dexOptions block you can also specify the heap size for the dex process, for example:

dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

These options are taken from a thread on the adt-dev mailing list (https://groups.google.com/forum/#!topic/adt-dev/r4p-sBLl7DQ) which has a little more context.

这篇关于使用 Gradle (Android Studio) 进行极长的构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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