File: build.gradle

package info (click to toggle)
android-platform-tools-base 2.2.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 113,836 kB
  • sloc: java: 696,390; xml: 45,920; cpp: 2,526; ansic: 1,432; sh: 508; lisp: 110; javascript: 108; makefile: 17
file content (64 lines) | stat: -rw-r--r-- 2,022 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 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" }

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.latestCompileSdk
    buildToolsVersion = rootProject.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)
}