Reducing gradle build time android

Having multiple products flavors in android project can take it toll over build time. Below is the pro tip to force gradle to build only your desired build.

in your app.gradle

android{

….

if (project.rootProject.file('dev.props').exists()) {
def devProps = new Properties()
devProps.load(project.rootProject.file('dev.props').newDataInputStream())
def currentDevFlavor = devProps.DEV_FLAVOR

project.logger.lifecycle('preffered falvour ===>' + currentDevFlavor)

android.variantFilter { variant ->

def flavorName = variant.getFlavors().get(0).name +
variant.getFlavors().get(1).name + buildType.name

project.logger.lifecycle('Variant Flavor Name ==>' + flavorName)

if (currentDevFlavor && (flavorName != currentDevFlavor)) {
project.logger.lifecycle('Ignoring ==>' + flavorName)
variant.setIgnore(true)
} else {
project.logger.lifecycle("Building..===>" + currentDevFlavor)
}
}
}

}

and create one file namely dev.props and add below line to it

DEV_FLAVOR= myappdevdebug //name of your desired build flavour with dimension

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Balwinder Singh Rajput
Balwinder Singh Rajput

Written by Balwinder Singh Rajput

Hi there 👋 Namaste 🙏🏻 .👨‍💻 developing apps from 12+ years. 👨‍🏫 IoT | E-commerce | baking domain expert.

No responses yet

Write a response