| // ATTENTION -- hash value of this file is checked in the corresponding |
| // integration test. Please make sure any changes you make here are |
| // backwards compatible. |
| |
| apply from: "../commonHeader.gradle" |
| buildscript { apply from: "../commonBuildScript.gradle", to: buildscript } |
| |
| apply plugin: 'com.android.application' |
| |
| android { |
| compileSdkVersion 21 |
| buildToolsVersion = rootProject.ext.buildToolsVersion |
| } |
| |
| public class GenerateCode extends DefaultTask { |
| @Input |
| String value |
| |
| @OutputFile |
| File outputFile |
| |
| @TaskAction |
| void taskAction() { |
| getOutputFile().text = |
| "package com.custom;\n" + |
| "public class Foo {\n" + |
| " public static String getBuildDate() { return \"${getValue()}\"; }\n" + |
| "}\n"; |
| } |
| } |
| |
| public class GenerateRes extends DefaultTask { |
| @Input |
| String value |
| |
| @OutputFile |
| File outputFile |
| |
| @TaskAction |
| void taskAction() { |
| getOutputFile().text = "<xml>${getValue()}</xml>\n" |
| } |
| } |
| |
| android.applicationVariants.all { variant -> |
| |
| // create a task that generates a java class |
| File sourceFolder = file("${buildDir}/customCode/${variant.dirName}") |
| def javaGenerationTask = tasks.create(name: "generatedCodeFor${variant.name.capitalize()}", type: GenerateCode) { |
| value new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")) |
| outputFile file("${sourceFolder.absolutePath}/com/custom/Foo.java") |
| } |
| |
| variant.registerJavaGeneratingTask(javaGenerationTask, sourceFolder) |
| |
| // create a task that generates an XML file class |
| File resFolder = file("${buildDir}/customRes/${variant.dirName}") |
| def resGenerationTask = tasks.create(name: "generatedResFor${variant.name.capitalize()}", type: GenerateRes) { |
| value new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")) |
| outputFile file("${resFolder.absolutePath}/xml/generated.xml") |
| } |
| |
| variant.registerResGeneratingTask(resGenerationTask, resFolder) |
| } |