Gradle在transformClassesWithDexForDebug上构建得慢 [英] Gradle build slow on transformClassesWithDexForDebug

查看:462
本文介绍了Gradle在transformClassesWithDexForDebug上构建得慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建我的Android应用大约需要90秒(fast),每次更新我的代码最多需要3分钟。这是一个完全浪费时间,因为它真的,我假设一个解决方案必须在可及范围内。我试图调查这个问题,并发现不同的博客帖子和SO答案的建议,其中大部分我已经尝试过。




  • 我拥有使用org.gradle.deamon = true的gradle.properties文件
  • 我使用Gradle Prefence在Android Studio上运行以进行离线工作(改进,但仍然很慢)

  • 在build.gradle,defaultConfig中,我将multiDexEnabled设置为false

  • 在命令行上运行(更快,但仍然很慢) li>在build.gradle,dexOptions中,我将preDexLibraries设置为false

  • 在gradle-wrapper.properties中,我获取最近的gradle版本(2.8)(显着速度变化发生在2.4上)



这个过程似乎需要很长时间,大约85%的构建时间是:app:transformClassesWithDexForDebug

这个过程究竟在做什么?我可以找到那些崩溃的人,但它对我来说很好,除了它需要很多时间。我是否需要它,因为我现在不需要Dex?

另外,我有13个依赖关系和3个testCompile依赖关系。我已经指出了具体的游戏包,所以我不编译我不需要的东西。如果我理解正确,gradle正在构建每个项目构建的所有这些库。如果这是正确的,有没有办法跳过?我可以自己将它们构建为封装库,并将它们包含在内,而不需要每次都处理它们?这可能会让我在将来对依赖关系进行更改时失去一些灵活性,但在这一点上,我觉得我在轻松等待gradle时每天会失去一个多小时。我不确定灵活性对我来说是否物有所值。



我期待得到关于如何改进构建过程的指导。

解决方案

升级到Android Studio 2.1和Android Gradle Plugin v2.1.0已经在很大程度上解决了我的这个问题。安装更新后的IDE后,系统会提示您更新您的Gradle插件。如果您的根build.gradle文件具有以下行,您将知道您拥有正确的版本:

  classpath'com.android .tools.build:gradle:2.1.0'

重要提示:除了升级之外,您还需要将分配给Gradle守护进程的内存量增加到2048mb,因此它可以执行这一昂贵的dex-ing步骤。为此,请将以下内容添加到您的根gradle.properties文件中:

  org.gradle.jvmargs = -Xmx2048m 

在上面的问题中,我的构建时间同样缓慢,但升级后我的构建速度急剧增加。

http://developer.android.com/tools/revisions/gradle-plugin.html


Building my Android app takes about 90 seconds ("fast"), up to 3 minutes for each update to my code. It's a complete waste of time as it really and I assume a solution must be within reach. I tried investigating the issue and found different blog-posts and SO answers with suggestions, most of which I've tried.

  • I have the gradle.properties file with org.gradle.deamon=true
  • I run on Android Studio with Gradle Prefence to do offline work (improved, but still slow)
  • I run on command line (which is faster, but still slow)
  • In build.gradle, defaultConfig, I have multiDexEnabled set to false
  • In build.gradle, dexOptions, I have preDexLibraries set to false
  • In gradle-wrapper.properties I fetch a recent gradle version (2.8) (the significant speed changes happened on 2.4)

The process that seems to take long, about 85% of total build time is :app:transformClassesWithDexForDebug

What is that process actually doing? I can find people who have crashes on it, but it works fine for me, except for the fact that it takes a lot of time. And do I need it, since I don't really need Dex at this point?

Also, I have 13 dependencies and 3 testCompile dependencies. I already point to specific play packages, so I'm not compiling stuff I don't need. If I understand things correctly, gradle is building all those libraries each project build as well. If that is correct, is there a way to skip that? Can I build them myself as wrapped-up libraries and include them without the need for them to be processed each time? That might make me lose some flexibility for future changes to dependencies, but at this point I feel like I'm losing over an hour a day easily on waiting for gradle. I'm not sure if flexibility is worth that much to me.

I'm looking forward to get any pointers on how I can improve my build process. Thank you in advance.

解决方案

Upgrading to Android Studio 2.1 and the Android Gradle Plugin v2.1.0 has largely fixed this problem for me. After installing the updated IDE, you should be prompted to update your Gradle plugin as well. You'll know you have the right version if your root build.gradle file has the following line:

classpath 'com.android.tools.build:gradle:2.1.0'

IMPORTANT: In addition to upgrading, you also need to increase the amount of memory allocated to the Gradle daemon to 2048mb, so it can perform this expensive dex-ing step in process. To do so, add the following to your root gradle.properties file:

org.gradle.jvmargs = -Xmx2048m

I had similarly slow build times as experienced in the question above, but after upgrading my build speeds increased dramatically. See the release notes for the Android Gradle Plugin v2.1.0 here for more info:

http://developer.android.com/tools/revisions/gradle-plugin.html

这篇关于Gradle在transformClassesWithDexForDebug上构建得慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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