-
-
Save mohsin/6be6fd7c978bdb87c9bf to your computer and use it in GitHub Desktop.
Gist for creating Dex file for class files in Android Library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The Task Below uses the Dex Tool to create classes.dex file for the archive | |
* This dex file can be then be loaded at runtime to prevent the 64K Dalvik Method Limit | |
*/ | |
import org.apache.tools.ant.taskdefs.condition.Os | |
android.libraryVariants.all { variant -> | |
def name = variant.buildType.name | |
if (name.equals(com.android.builder.BuilderConstants.DEBUG)) { | |
return; // Skip debug builds. | |
} | |
log.info("========================================") | |
log.info("Starting Variant Build") | |
log.info("Variant Name: ${variant.name}") | |
log.info("Build Type Name: ${variant.buildType}") | |
log.info("Variant: ${variant}") | |
log.info("========================================") | |
String cmdExt = Os.isFamily(Os.FAMILY_WINDOWS) ? '.bat' : '' | |
def task = project.tasks.create ("dex${name.capitalize()}", Exec) | |
task.dependsOn variant.javaCompile | |
task.commandLine "${System.env.ANDROID_HOME}/build-tools/${BUILD_TOOLS_VERSION}/dx${cmdExt}", '--dex', | |
"--output=${buildDir}/classes/${variant.name}/classes.dex", | |
"${buildDir}/classes/${variant.name}" | |
// Make sure we run our Dexing task before the packageReleaseJar Task | |
Task packageJar = project.tasks.getByName("package${name.capitalize()}Jar") | |
packageJar.dependsOn(task) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment