Hi there!..

I was facing this issue where Gradle build time was way too much, and on googling some of the simple ways of reducing this, i was super happy 🙂 .

This blog, will only list the steps (all in one place) that might solve your issues immediately, but if the issue still persists, you might as well want to write a gradle script on your own.

  1. To stop android studio from indexing every now and then, which does indeed slow the build time, do the following:
    a. Go to Preferences in the main menu (Android studio menu)
    b. Click Appearance and Behavior
    c. Go to System Settings
    d. Under Synchronization uncheck "Synchronize files on frame or editor tab activation"
    e. Apply the changes
  2. You can make the following changes to gradle to make it build faster:
    a. Under the same Preferences menu option, click on Build, Execution, Deployment
    b. Tap on Gradle
    c. Check Offline work
    
    d. Tap on compiler then
    e. Under command-line options: type in "--offline"
  3. Add the following to “gradle.properties” file in the root folder of the main application
    org.gradle.daemon=true
    org.gradle.parallel=true
  4. Invalidate caches and restart android studio, you should be fine now.

For me, the build time reduced drastically from 4min / 5min to almost 2minutes.

Hope that helps!

P.S: This does have its own drawbacks, with respect to offline gradle, and synchronization set to off. You might face cases where in there is a new dependency added and it is not avaialable offline and you would get an error message. In scenarios as such, it is always appropriate to uncheck offline gradle mode. Or you might have updated the xml, and the id is still not found, in such cases you would have to manually build the project first to reflect these changes, thus again, it is always better to let android studio do that for you immediately 😉

Advertisements