Amr Ayman

How To Make Android Gradle Build Faster
🕑 6 mins
If you’re tired of waiting for ages for your Android project to build just for testing a simple change, you’re not alone. Gradle can feel slow—especially as your app grows. The pain of wasting time building project the nightmare only android developers know! So, I will tell you A few smart tweaks that can make your builds faster.
In this post, we’ll go through a quick tips to boost your Gradle performance.
1- Open gradle.properties in your project
2- Add the following Configs:
– Heap Size
Markdown
org.gradle.jvmargs=-Xmx6144m -Dfile.encoding=UTF-8This allocates a maximum heap size of 6144 megabytes (6 GB) to the Gradle Daemon. Increasing the heap size can improve build performance for large projects by providing more memory for Gradle to operate. You can make it lower or more if needed.
– Gradle Daemon
Markdown
org.gradle.daemon=trueThe Daemon is a long-lived background process that keeps build information in memory. Using the Daemon significantly speeds up subsequent builds.
– parallel execution
Markdown
org.gradle.parallel=true
org.gradle.workers.max=8This enables parallel execution of tasks within a project. If your project has multiple modules, Gradle can execute tasks in these modules concurrently utilizing 8 parallel workers.
– BUILD CACHING
Markdown
org.gradle.caching=true
org.gradle.configuration-cache=trueThis feature speeds up builds by caching the tasks & result of the configuration phase. The configuration phase is where Gradle builds the task graph for your project.
Full Config File
Markdown
# Custom Gradle Configs by Amrk000
# Project-wide Gradle settings for Android
# Gradle settings configured through the IDE *will override*
# For more details: http://www.gradle.org/docs/current/userguide/build_environment.html
# Defaults:
# AndroidX package structure to make it clearer which packages are bundled: https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
# Edited:
# Gradle Speed Up Configs
# This allocates a maximum heap size of 6144 megabytes (6 GB) to the Gradle Daemon.
# Increasing the heap size can improve build performance for large projects by providing more memory for Gradle to operate.
org.gradle.jvmargs=-Xmx6144m -Dfile.encoding=UTF-8
# The Daemon is a long-lived background process that keeps build information in memory. Using the Daemon significantly speeds up subsequent builds
org.gradle.daemon=true
# This enables parallel execution of tasks within a project. If your project has multiple modules, Gradle can execute tasks in these modules concurrently
org.gradle.parallel=true
org.gradle.workers.max=8
# This feature speeds up builds by caching the tasks & result of the configuration phase. The configuration phase is where Gradle builds the task graph for your project
org.gradle.caching=true
org.gradle.configuration-cache=trueYou can make these configs default globally for all projects by creating gradle.properties containing the needed configs in C:\Users\USERNAME\.gradle directory.



