Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio gradle's "calculate task graph" takes too long

When building app in Android Studio, it takes too long (besides I use offline mode, latest gradle, etc).

I investigate, and see progress of each task, where most time is spent in Calculate task graph item.

enter image description here

Every single gradle task that I choose from Gradle tool window spend at least 9 seconds in this Calculate task graph.

How can I speed up this task, and why it takes so long, when other gradle tasks are usually cached (UP-TO-DATE)? I could possibly build much faster, but each app build adds 10 seconds, which is killer of productivity.

Any advice is welcome. Thanks.

like image 972
Pointer Null Avatar asked Dec 13 '16 08:12

Pointer Null


1 Answers

Inside "Calculate task graph" phase Gradle also appears to be resolving dependencies (not sure why this isn't in its own separate time slot, it could be a bug). That means that you can follow Gradle's guide to dependency resolution performance.

What helped in my project:

  • Remove any unused repositories (removing mavenLocal() made the biggest difference)
  • Remove any SNAPSHOT libraries and repositories that contain snapshots (use stable versions instead)
  • Interestingly enough, disabling Android Plugin's jetifier (set android.enableJetifier=false in gradle.properties) seems to also help significantly but of course that means that you cannot depend on libraries that did not migrate to AndroidX yet. It appears this is a bug in jetifier.
like image 128
Matej Drobnič Avatar answered Oct 05 '22 22:10

Matej Drobnič