This article is originally published in personal Blog Android accelerated build solution comparison – Yong’s Blog
Is there any way to speed up Gradle builds in Android Sudio? Since I happen to be developing and maintaining Freeline, I’ve also put together a list of various build-acceleration options and comparisons on Android.
Instant Run
-
Pros
- Google’s officially supported incremental compilation scheme continues to improve with each iteration of Android Studio
- Relatively stable, zero configuration, virtually no intrusive impact
- It can compile in seconds, very fast
-
Cons
- There are limitations on what can be changed, please refer to the official documentation for details
- In addition to resource changes, modifying Java files will restart the entire application from a Launcher Activity, which is inconvenient if you are developing a deep UI page (of course, you can also restart the Activity manually by shutting it down, However, it may cause the problem that the application is not updated after compilation. For specific methods, please refer to the official documentation.)
- Incremented code does not support debugging
- The support for complex engineering structures is not high
- Do not support the Kotlin
-
A link to the
Buck/okbuck
JRebel for Android
-
Pros
- An incremental compilation solution for Android that predates Instant Run, ZeroTurnRound has a large accumulation of hot deployment practices on JVMS
- Zero configuration, just install the Android Studio plugin, and it runs immediately
- Compared to the wide range of support for Instant Run, see the link
- Retrolambda is supported with some popular annotation libraries
- Dynamic loading at the bytecode level theoretically supports almost any JVA-BASED language, including Kotlin, Groovy, etc
-
Cons
- Charge, the price is higher, can refer to the link
- Do not support the databinding
- Only the paid version can debug, there is a special debug tool
- After Crash, full compilation is required again, and the speed of full compilation and installation is very slow
-
A link to the
Freeline
LayoutCast is also a common solution to accelerate compilation, but it does not support multi-module projects, so it is only an incremental compilation prototype. It usually needs to be modified to be used in complex projects, so it cannot meet the requirements of out-of-box, so I will not add the above comparison.
Now let’s talk about how to choose the above scheme.
If the team is all-Mac, and the project is just getting started or has no historical baggage, consider moving the build system to Buck from the start so that you don’t have to run into slow builds as the project expands. For those projects that are already of a certain magnitude and need to be migrated to Buck, time costs need to be taken into consideration. Even with Okbuck’s help, it will take a lot of time to migrate and build a system for a large project, and you may even need to modify buck’s source code to suit your own project. In addition, when using Buck, it is best to break up the engineering module into more small units, which can significantly improve the overall compilation speed. The problem with Buck is that it is an independent build system that is completely different from Gradle. This means that plugins that can be applied to Gradle projects need to be ported to Buck separately. There may be a difference between a debug package typed with Buck and a Gradle package typed with Gradle. You cannot simply type debug packages with Buck and then build release packages using Gradle.
For small projects by individual developers, Instant Run is almost adequate. Those of you who are not strapped for cash, or who use jVA-based languages such as Kotlin, can also try JRebel for Android (if you’re willing to pay, there’s only a free trial period otherwise).
[Hard wide implant]
If the above situation is not enough, you are also welcome to experience Freeline. Freeline’s advantages have been mentioned above, and it can basically cover most cases of daily development. Freeline basically handles only the files that have changed each compilation, be it Java files or resource files, and the process is truly incremental compilation. There are also third-party developers in the community who provide IDE plug-ins for Android Studio that can be seamlessly integrated into daily development. After using Freeline, we basically said goodbye to hot laptops and crazy fans except when we compile at full volume, and we will no longer be unable to use Android Studio cards under various compile conditions.
Since Freeline became open source, many Android applications have been connected to Freeline to speed up the compilation process for daily development. Of course, Freeline isn’t a perfect solution. There are also examples of getting started and giving up. For example, Freeline often had to clear the cache to develop a feature, but after clearing the cache, Freeline could only compile in full and eventually gave up Freeline. In essence, Freeline is a hack scheme based on Gradle to build a system, so there are some compatibility problems, which is the fundamental reason why it is not stable enough and not a perfect solution.
Freeline is still being developed and improved, and incremental compilation deployment support for databinding and NDK will be added next. If you encounter any problems in the access process or the use process, you can raise an issue on Github. We will help you solve it as soon as possible.
We hope Freeline can bring different development efficiency and experience to Android developers. If you like our project, please add a star to us on Github: Github-Alibaba/Freeline: Freeline is a fast build and deployment tool for Android
Is there any way to speed up Gradle builds in Android Sudio? – Answer by Yong Huang – Zhihu