summaryrefslogtreecommitdiff
path: root/platform/android/java/build.gradle
blob: 99ffa937b04936dcb1b51921f2cd5e5d3051744c (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
apply from: 'app/config.gradle'

buildscript {
    apply from: 'app/config.gradle'

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath libraries.androidGradlePlugin
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

def binDir = "../../../bin/"

/**
 * Copy the generated 'android_debug.apk' binary template into the Godot bin directory.
 * Depends on the app build task to ensure the binary is generated prior to copying.
 */
task copyDebugBinaryToBin(type: Copy) {
    dependsOn ':app:build'
    from('app/build/outputs/apk/debug')
    into(binDir)
    include('android_debug.apk')
}

/**
 * Copy the generated 'android_release.apk' binary template into the Godot bin directory.
 * Depends on the app build task to ensure the binary is generated prior to copying.
 */
task copyReleaseBinaryToBin(type: Copy) {
    dependsOn ':app:build'
    from('app/build/outputs/apk/release')
    into(binDir)
    include('android_release.apk')
}

/**
 * Copy the Godot android library archive debug file into the app debug libs directory.
 * Depends on the library build task to ensure the AAR file is generated prior to copying.
 */
task copyDebugAAR(type: Copy) {
    dependsOn ':lib:build'
    from('lib/build/outputs/aar')
    into('app/libs/debug')
    include('godot-lib.debug.aar')
}

/**
 * Copy the Godot android library archive release file into the app release libs directory.
 * Depends on the library build task to ensure the AAR file is generated prior to copying.
 */
task copyReleaseAAR(type: Copy) {
    dependsOn ':lib:build'
    from('lib/build/outputs/aar')
    into('app/libs/release')
    include('godot-lib.release.aar')
}

/**
 * Generate Godot custom build template by zipping the source files from the app directory, as well
 * as the AAR files generated by 'copyDebugAAR' and 'copyReleaseAAR'.
 * The zip file also includes some gradle tools to allow building of the custom build.
 */
task zipCustomBuild(type: Zip) {
    dependsOn 'copyDebugAAR'
    dependsOn 'copyReleaseAAR'
    from(fileTree(dir: 'app', excludes: ['**/build/**', '**/.gradle/**', '**/*.iml']), fileTree(dir: '.', includes: ['gradle.properties','gradlew', 'gradlew.bat', 'gradle/**']))
    include '**/*'
    archiveName 'android_source.zip'
    destinationDir(file(binDir))
}

/**
 * Master task used to coordinate the tasks defined above to generate the set of Godot templates.
 */
task generateGodotTemplates(type: GradleBuild) {
    tasks = [
            // Copy the generated aar library files to the custom build directory.
            'copyDebugAAR', 'copyReleaseAAR',
            // Zip the custom build directory.
            'zipCustomBuild',
            // Copy the prebuilt binary templates to the bin directory.
            'copyDebugBinaryToBin', 'copyReleaseBinaryToBin',
    ]
}