Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@artem-zinnatullin
Created July 17, 2014 07:30
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save artem-zinnatullin/28ac8ea1494825832f23 to your computer and use it in GitHub Desktop.
Save artem-zinnatullin/28ac8ea1494825832f23 to your computer and use it in GitHub Desktop.
Gradle & Android: Disable/Enable preDexing
// add this to the general build.gradle, not in the subproject's build.gradle
// improved version of Xavier's tip http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance.
// usage example default, preDex will be enabled: gradle clean build
// usage example disabling preDex: gradle clean build -PpreDexEnable=false
// preDexEnable parameter's value can be set as property of Continuous Integration build config
// this is the main difference from Xavier's workaround where he doing only hasProperty check
project.ext {
if (project.hasProperty('preDexEnable')) {
project.ext.preDexLibs = project.properties['preDexEnable'].equals('true')
} else {
project.ext.preDexLibs = true // pre dexing should be true by default
}
println('PREDEX ' + (project.ext.preDexLibs ? 'ENABLED' : 'DISABLED')) // goes to build log or console output
}
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment