简体   繁体   English

Android Studio Gradle同步/构建性能

[英]Android Studio Gradle Syncing/Building Performance

These are a series of questions for Android Studio programmers who have worked on large projects before. 对于以前从事大型项目的Android Studio程序员,这是一系列问题。 So, before I list the questions let me explain why I'm asking. 因此,在我列出问题之前,让我先解释为什么要问。

I couldn't help but notice it taking 36+ seconds for Gradle to sync and build for me to start programming every time I launch AS. 我忍不住注意到Gradle花费了36秒钟以上的时间来同步和构建,使我每次启动AS时都可以开始编程。 It's not so much a problem now, but how about when the project starts to get over 26,000+ lines of code? 现在这不是什么大问题,但是该项目何时开始获得超过26,000多行代码呢? So, now my real questions are: 所以,现在我真正的问题是:

1) Do large projects take significantly longer for Gradle to sync and build than a small one? 1)Gradle同步和构建大型项目是否比小型项目花费更长的时间?

2) If it does, are there any levels of refactoring/error catching that I could bypass in the sync/build to make the process faster in the long run? 2)如果可以,从长远来看,我可以在同步/构建中绕过任何级别的重构/错误捕获以使过程更快吗?

3) My computer can run any game on full ultra quality. 3)我的电脑可以以超高质量运行任何游戏。 Is a system spec that makes compiling and programming language processing faster than a gaming spec? 是一种使游戏语言的编译和编程速度更快的系统规格?

Thanks to all who contribute, and you will be acknowledged (with at least a vote) regardless of whether you can answer all the questions or not! 感谢所有贡献者,无论您能否回答所有问题,您都会得到认可(至少要投票)!

  1. Yes, larger projects will take longer to sync and build. 是的,较大的项目将需要更长的时间来同步和构建。 Lines of code is a contributing factor, as well as dependencies, number of assets, etc. Gradle is also somewhat infamous for being a bit slow. 代码行以及相关性,资产数量等都是一个促成因素。Gradle的运行速度有点慢,也因此而臭名昭著。

  2. This is dependent on your individual Gradle configuration. 这取决于您的个人Gradle配置。 Removing unneeded steps (if you have configured some), such as signing the APK, may also help. 删除不必要的步骤(如果已配置了某些步骤),例如对APK进行签名,也可能会有所帮助。 'Instant Run' is very quick for small changes but is somewhat untrustworthy. 小变化时,“即时运行”非常快,但有些不可信。 There's no way to 'skip' steps of compilation - if a recompile is needed, a recompile is needed. 无法“跳过”编译步骤-如果需要重新编译,则需要重新编译。 Trust that the compiler and IDE will optimise out any unnecessary steps and ensure that you are not asking for any unnecessary extra steps. 相信编译器和IDE将优化所有不必要的步骤,并确保您不要求任何不必要的额外步骤。

  3. Gaming computers generally have fairly beefy processors, which are the main component used to sync and build a project. 游戏计算机通常具有相当强大的处理器,这是用于同步和构建项目的主要组件。 The disk read speed of your hard drive will also be a factor - SSDs will be much faster than platter drives - but it's comparatively much less important than your processor. 硬盘驱动器的磁盘读取速度也将是一个因素-SSD的速度将比盘片驱动器快得多-但它比处理器的重要性要低得多。 Your video card, the other big component in a gaming PC, will not be used at all to build. 您的视频卡(游戏PC中的另一个重要组成部分)将完全不会被使用。 A solid gaming PC will be more than adequate for development. 可靠的游戏PC足以满足开发需求。

There are a few ways to shave time off your Gradle build times ( for example ) but build times will always be a reality. 有几种方法可以节省Gradle构建时间( 例如 ),但是构建时间永远是现实。

Lucky you. 幸运的你。 Gradle speeds have increased considerably over the last two years. 在过去的两年中,Gradle的速度已大大提高。 As of today, even though still a bit slow, I'm pretty satisfied with the speed. 到今天为止,尽管仍然有点慢,但我对速度还是很满意的。 Anyhow. 无论如何。 Regarding your questions, here's my two cents: 关于您的问题,这是我的两分钱:

  1. Yes. 是。 But it's not a linear "function". 但这不是线性的“函数”。 I haven't come across any project that takes more than 3 or 4 mins tops when configured correctly, one especially was pretty big. 正确配置后,我还没有遇到任何需要超过3或4分钟的时间的项目,特别是其中一个很大的项目。

  2. The only way to "speed up" the process is to allocate more memory. “加速”进程的唯一方法是分配更多的内存。 There are two ways here, inside the inner (module) gradle file, you can do this: 这里有两种方法,可以在内部(模块)gradle文件中,执行以下操作:

dexOptions { javaMaxHeapSize "5g" }

Or you can define a field inside the gradle.properties file: 或者,您可以在gradle.properties文件中定义一个字段:

org.gradle.jvmargs=-Xmx5632M

  1. There is no system spec that I know of that will increase performance, but sounds like you got a pretty good system and you will not run into any troubles. 我不知道会提高性能的系统规格,但是听起来您的系统不错,而且不会遇到任何麻烦。 A lot of progress has been made in the field. 在该领域已经取得了很多进展。

Enjoy developing. 享受发展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM