Struggling with Slow Android Build 🥺?

Aalap Rawat
3 min readJul 10, 2021

We all know how slow gradle build can kill your precious productive hours and make you unproductive. Each slow build results in the loss of precious time. If each incremental build in your app is taking 1 minute extra for the build. And during a day you build your apps for more than 40–50 times then this will result in a loss of 1 hour per day(Roughly saying could be more). This issue is so widely know that online community have come up with various funny meme on this.

Here at WorkIndia, WorkIndia Job Search App is build on android and for the dry run or any incremental build our project was taking way too much time to build and we needed a solution. So is it possible?

YES !!!! YES !!! YES !!!

You really want to know what we did to reduce our build time 5–8x and increased our productivity.

First I will show the profile reports from our old repositories

First build — 2m 24sec, Second build — 1min6s, 3rd build 2.8s

Additional Project Compilation

MaterialTapTargetPrompt was addition module in our project which compiles everytime a build occurs

Now, First thing we did was removing dependency which we imported as project, So every time our projects build, This project needed to be build first and this would result in more time added to build, We removed this module from the project and added its dependency

THE CHANGE

Adding this line, helped us use the components from previous builds and making build faster

org.gradle.caching=true

Updating to the new gradle and gradle plugin helped us achieve faster speed

Previously We were using gradle 5.6, Now updated it with the latest gradle and voila!!! We have achieved a faster build time.

First build — 14sec, Second build — 3s, 3rd build 2.7s

The Result was drastic just by removing the dependency and updating to the new gradle and gradle plugin.

Now, The additional compilation of MaterialTapTargetPrompt doesn’t occur and provides a smooth and fast build every time.

Resolution of only 1 project on every build

Some Additional Tips

If any dependencies is having attributes as 1.2.+, Rename it something with a fixed version like 1.2.2 this will also help in reducing the build time.

So, the time wasted which was 1 hour per day is reduced 8–10x, making it 10 min of build everyday and give you more time to bring the change you want through your app.

During Migration to new gradle, we were facing some issues on the production build that is while using pro-guard obfuscation.

java.lang.RuntimeException: Unknown animation name: x

We solved the problem by adding this line in pro-guard rules.

-keepclassmembers class **.R$* {
public static <fields>;
}

Hope, This article will help you and your team.

Happy Coding!!!!

--

--