4

The following measures were taken to speed up gradle build from this (SO post)

  1. org.gradle.parallel=true, org.gradle.daemon=true
  2. build from terminal and not from android Studio
  3. building with ./gradlew assembleDebug --offline

Problem:

  1. Even after these measures build times can take upto 6-8 minutes for a single line of code change! and during this time computer mostly freezes and nothing else can be done except to stare at the terminal. I've noticed that "app:dexDebug" takes a lot of time in this. What are the possible causes?

Relevant files:

  1. Terminal build dump
  2. build.gradle(app)
  3. build.gradle(project)

System details:

  1. Android Studio 1.2.2
  2. Description: Ubuntu 14.04.2 LTS
Community
  • 1
  • 1
Ankan-Zerob
  • 3,378
  • 2
  • 18
  • 25

3 Answers3

2

You can try disabling your lint checks by adding this code to your build.gradle

tasks.whenTaskAdded { task ->
    if (task.name.toLowerCase().contains("lint")) {
        task.enabled = false
    }
}

Also you can use the --profile parameter to export a html report of what's taking so long in your build time

EDIT: removed the debug check

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
  • trying that right now. I'm adding this to the project build.gradle and running with --profile. – Ankan-Zerob Jul 03 '15 at 10:37
  • Good luck. Also add the report to the original post so other people can help you :) – Pedro Oliveira Jul 03 '15 at 10:39
  • thanks for the profile tip! some ugly task execution times have come up: app:preDexDebug 3m6.93s :app:dexDebug 44.510s :app:compileDebugJava 28.332s :app:packageDebug 22.577s – Ankan-Zerob Jul 03 '15 at 10:57
  • Are you making a clean build? If so you can use `preDexLibraries = false`. http://stackoverflow.com/a/21136780/3410697. What about proguard/minify? Is it enabled? – Pedro Oliveira Jul 03 '15 at 11:01
0

We had a similar problem: our build took about 4 minutes. After some research, we get next steps:

Try turning on offline work in your Gradle settings (Ctrl + Alt + S for the Settings, then Build Tools -> Gradle settings). Usually, we do not update libraries so often and Gradle will not check that they are up to date.

Multidex increases the time for build: Android documentation. To mitigate this, you can add additional flavors for debug and production builds, setting for debug builds minSdk = 21 (suggestion from official site).

If you have several modules in project, try to flatten them into one or at least extract "Library project" and connect it as .aar

As a result, our build time decreased to about minute - minute and a half. Hope these suggestions will help you too.

And if we will talk about small changes, starting from Android Studio 2.0, it is possible to use Instant run and Incremental build, which makes small changes in method or layout even faster.

Gaket
  • 6,533
  • 2
  • 37
  • 67
-5

Understand that Gradle Build has nothing to do with your CPU Speed or RAM. The reason why the Build gets slower in your PC is due to your Internet Connection. The build can take nearly ~100 MB approx. of data to complete it's process. Even if your Internet Connection is fast and your connection's PING speed is slow, it takes more time.

Praveen Thirumurugan
  • 977
  • 1
  • 12
  • 27