How to Speed up Gradle build process in Android Studio?

Before getting info speed up gradle build, we should know that, what is gradle build.Before eclipse, we dont have any automation scripts to build java and XML code to android apk. So that we used commands to generate apk. To optimize this process, gradle build come into the picture. Gradle is automated script to build and generate apk using android studio.

What is Gradle sync ?

Gradle sync is automation process to download dependencies which are declare in gradle file. A simple example as shown below −


How to speed Gradle Build in android?

Step 1 − Open and add the following code as shown below

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.daemon = true
org.gradle.parallel = true
org.gradle.configureondemand = true
org.gradle.jvmargs=-Djava.awt.headless = true -Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# org.gradle.parallel=true

The above code going to increase build JVM MaxPermSize(gives 2GB max memory to JVM complier) and execute in parallel.

Step 2 − Now use the following process to speed up gradle.

Now open File → Setting →Build,Excution,Deployment → Gradle and check offline work as shown below −

Gradle Speedup

Because every gradle going to sync with internet resources. So when you click on offline work, it will sync with offline resources as well.

Step 3 − Now use the following process to speed up gradle.

Now open File → Setting →Build,Excution,Deployment → complier and check all check boxs as shown below −

Speedup Gradle

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started