Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle builds really slow with a multi-project structure

Tags:

When building with gradle on a multi-project setup containing roughly 140 projects/libraries, the build time took 1 hour and 22 minutes. And i was using --parallel. And our ANT build takes less than 20 minutes without parallel building.

Here is exactly what i did.

./gradlew clean ./gradlew build --parallel 

I did a little testing it seems like the dexing is taking the longest amount of time. Is there a way to get the gradle process to re-use the stuff it has already dexed? If the libraries have already been built, it should re-use the already dexed libraries.

I saw the option --no-rebuild, but when i run with that option it says the following

File '/path/to/project/build/libs/project.aar' specified for property 'bundle' does not exist. 

I replaced the file path and project name with generic stuff.

Using Gradle 1.9-rc-3


Additional information(15 Jan 2014):

preDexDebug and preDexRelease took a VERY long time on each project. Much longer than any other task.


Progress(15 Jan 2014):

Ok, for now, i put preDexLibraries = false into all of the build.gradle files. However, i still would like to know a centralize place that i can put that entry and it affect all the other build.gradle files.

However, now dexRelease and dexDebug are taking a long time. Is there any way that i can tell the build to only do the dexDebug or dexRelease and skip the other one?


Progress(15 Jan 2014):

Using assembleDebug worked. However, it still seems like it is not re-using the already dexed libraries. Because dexing is still taking forever. It takes about a minute for each project. Is there a way to get gradle to re-use the already dexed libraries? Or is there a different reason why the build is still taking about an hour? Our ANT process takes less than 15 minutes.

like image 950
prolink007 Avatar asked Jan 14 '14 22:01

prolink007


People also ask

Why is my Gradle build so slow?

Dynamic Dependencies slow down your build since they keep searching for the latest builds every time. To improve the performance we need to fix the version in place. Use only those dependencies that you need.

Is Gradle multithreaded?

In parallel mode, Gradle will run multiple executor threads, which can execute tasks from different projects in parallel. By default Gradle will create one executor thread for each CPU core on your machine, but this is configurable.

What is Gradle multi-project build?

A multi-project build in Gradle consists of one root project, and one or more subprojects. This is the recommended project structure for starting any Gradle project. The build init plugin also generates skeleton projects that follow this structure - a root project with a single subproject.

Does Gradle run tasks in parallel?

Parallel executionBy using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects. You could see big improvements in build times as soon as you enable parallel builds.


2 Answers

Doing a clean you actually delete the already predexed libraries.
As suggested in this thread you could save some time on clean builds by disabling predexing (because at the next build they will be deleted):

android {   dexOptions {     preDexLibraries = false   } } 
like image 74
rciovati Avatar answered Sep 18 '22 05:09

rciovati


According to this post.

Right now each project will pre-dex its dependencies on its own. This means 2 components depending on the same library will both run pre-dex on that library's classes.jar which is silly. We're looking at fixing this.

like image 44
prolink007 Avatar answered Sep 20 '22 05:09

prolink007