aboutsummaryrefslogtreecommitdiff
path: root/build.gradle
blob: 9659eeac0944d9f29f022c38d880abc5fa5ceb2f (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
System.setProperty("file.encoding", "UTF-8")

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        mavenLocal()
        maven { url 'https://jitpack.io' }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.github.menny:GradleVersion:1cd6d47894028c58924d80238068aaf579a04663'

        classpath 'com.github.triplet.gradle:play-publisher:2.0.0'

        //this is needed for publishing
        classpath 'com.novoda:bintray-release:0.9'
    }
}

apply plugin: 'net.evendanan.versiongenerator'

def generators = [
        new net.evendanan.versiongenerator.generators.EnvBuildVersionGenerator.CircleCi(1000, -1600),
        new net.evendanan.versiongenerator.generators.GitBuildVersionGenerator(0, 0),
        new net.evendanan.versiongenerator.generators.StaticVersionGenerator()
]

def versionData = versionGenerator.generateVersion(4, 0, 0, generators)
rootProject.version = versionData.versionName

rootProject.file('.generated_pack_version').write(versionData.versionName)

def languagePacks = new ArrayList<String>()

tasks.register("generateMarkDownOfLanguagePacks") {
    group "AnySoftKeyboard"
    description 'Printing a MarkDown-friendly list of languages'

    doLast {
        println("## Languages in this repo")
        println("We have ${languagePacks.size()} language packs in this repo:")
        println()
        languagePacks.each { println(it) }
    }
}

static <T> T getExtValue(Project proj, String key, T defaultValue) {
    if (proj.hasProperty(key)) {
        return proj.getProperties().get(key)
    } else {
        return defaultValue
    }
}

static Object getExtValue(Project proj, String key) {
    return getExtValue(proj, key, null)
}

subprojects {
    it.group "com.anysoftkeybaord${it.parent.path.replace(':', '.')}"
    it.version = rootProject.version
    it.afterEvaluate { project ->
        def languageName = project.parent.name

        //ANDROID BASICS
        if (project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('com.android.application')) {
            project.android {
                compileSdkVersion 28
                buildToolsVersion '28.0.3'

                defaultConfig {
                    minSdkVersion 9
                    targetSdkVersion 28
                    versionCode versionData.versionCode
                    versionName versionData.versionName
                }
            }
        }

        if (project.plugins.hasPlugin('com.android.application')) {
            project.android {
                defaultConfig {
                    applicationId "com.anysoftkeyboard.languagepack.${languageName}"
                }

                applicationVariants.all { variant ->
                    variant.outputs.all {
                        outputFileName = "ASKLangPack-${languageName}-${versionData.versionCode}.apk"
                    }
                    variant.assemble.doLast { assemble ->
                        copy {
                            from variant.outputs*.outputFile
                            into "${rootDir.absolutePath}/language-packs-apk/${variant.dirName}/"
                        }
                    }
                }
            }
        }

        //PUBLISH TO PLAY-STORE
        if (project.plugins.hasPlugin('com.android.application')) {
            def image = "<img src='languages/${project.parent.name}/apk/flag/{{IMAGE_FILENAME}}' height='16'>&nbsp;"
            if (project.file("flag/flag.png").exists()) {
                image = image.replace("{{IMAGE_FILENAME}}", "flag.png")
            } else if (project.file("flag/flag.svg").exists()) {
                image = image.replace("{{IMAGE_FILENAME}}", "flag.svg?sanitize=1")
            } else {
                image = ""
            }
            def packReadMeDetails = "* ${image}${languageName.capitalize()}: [Source](languages/${project.parent.name})"

            project.android {
                signingConfigs {
                    release {
                        def keystoreFile = file("/tmp/language_pack.keystore")
                        if (keystoreFile.exists()) {
                            storeFile keystoreFile
                            storePassword System.getenv("PACKS_ALL_KEY_STORE_FILE_PASSWORD")
                            keyAlias getExtValue(project, "override_release_key_alias", System.getenv("PACKS_ALL_KEY_STORE_FILE_DEFAULT_ALIAS"))
                            keyPassword System.getenv("PACKS_ALL_KEY_STORE_FILE_DEFAULT_ALIAS_PASSWORD")
                            println "Using '${storeFile.absolutePath}' to release APK ${path} (with alias '${keyAlias}')."
                        } else {
                            println "Could not find '${keystoreFile.absolutePath}' file. Can not sign release APK with release keystore! Using debug."
                            initWith signingConfigs.debug
                        }
                    }
                }

                buildTypes {
                    release {
                        signingConfig signingConfigs.release
                        zipAlignEnabled true
                        debuggable false

                        minifyEnabled false
                    }
                }
            }

            if (project.ext.shouldBePublished) {
                packReadMeDetails += " • [Play Store](https://play.google.com/store/apps/details?id=${project.android.defaultConfig.applicationId})"
                println("Project ${path} is marked for publishing")

                project.apply plugin: 'com.github.triplet.play'

                play {
                    // you can promote from command-line by specifying the track to promote to:
                    // ./gradlew :languages:hebrew:apk:promoteReleaseArtifact -DpublishTrackOverride=beta
                    track = System.getProperty('publishTrackOverride', 'alpha')
                    serviceAccountEmail = System.getenv().getOrDefault('PUBLISH_APK_SERVICE_ACCOUNT_EMAIL', 'dummy@example.com')
                    serviceAccountCredentials = file('/tmp/apk_upload_key.p12')
                }
            } else {
                println("Project ${path} is NOT marked for publishing")
            }

            languagePacks.add(packReadMeDetails)
        }

        //GENERATING ICONS
        if (project.plugins.hasPlugin('com.android.library') && name != "base") {
            def generateIconsTask = project.tasks.register('generateLanguagePackIcons') {
                group "AnySoftKeyboard"
                description 'Creating icons for AnySoftKeyboard language pack library'
            }

            [['xxxhdpi', 96, 80], ['xxhdpi', 72, 62], ['xhdpi', 48, 40], ['hdpi', 36, 32], ['mdpi', 24, 22]].each { dimens ->
                def statusIcon = project.tasks.register("generateStatusIcon_${dimens[0]}", Exec) {
                    commandLine "${rootDir.absolutePath}/scripts/generate_status_icon.sh", project.ext.status_icon_text, languageName, "${dimens[1]}", "${dimens[2]}", "${projectDir.absolutePath}/src/main/res/drawable-${dimens[0]}"
                }

                generateIconsTask.configure { dependsOn.add(statusIcon) }
            }
        }

        if (project.plugins.hasPlugin('com.android.application')) {
            def imageAssetsFolder = new File(new File(rootDir, "StoreStuff"), "assets")
            if (!imageAssetsFolder.exists()) {
                throw new IllegalStateException("store assets folder '${imageAssetsFolder.absolutePath} does not exist!")
            }

            def generateLogoTask = project.tasks.register('generateStoreLogoIcon', Exec) {
                group "AnySoftKeyboard"
                description 'Creating icons for AnySoftKeyboard language pack APK'

                commandLine "${imageAssetsFolder.absolutePath}/logo-base/generate.sh", projectDir.absolutePath, buildDir.absolutePath, "${imageAssetsFolder.absolutePath}/logo-base"
            }

            def launcherAssetsDir = "${imageAssetsFolder.absolutePath}/launcher-base"
            [['xxxhdpi', 64, 24], ['xxhdpi', 48, 20], ['xhdpi', 36, 10], ['hdpi', 30, 4], ['mdpi', 22, 1]].each { dimens ->
                def convert = project.tasks.register("generateLauncherIcon_${dimens[0]}", Exec) {
                    commandLine "${launcherAssetsDir}/generate.sh", projectDir.absolutePath, buildDir.absolutePath, "${dimens[0]}", "${dimens[1]}", "${dimens[2]}", launcherAssetsDir
                }

                generateLogoTask.configure { dependsOn.add(convert) }
            }
        }

        if (getExtValue(project, "shouldGenerateDictionary", true) && project.plugins.hasPlugin('com.android.library') && name != "base") {
            //project.apply plugin: 'makedictionary'
        }

        //CHECKS
        if (project.plugins.hasPlugin('com.android.library') || project.plugins.hasPlugin('com.android.application')) {
            project.android {
                lintOptions {
                    htmlOutput file("${buildDir.absolutePath}/reports/lint/${path.substring(1).replace(':', '-')}-lint-results.html")
                    lintConfig rootProject.file('configs/lint.xml')
                }
            }
        }
    }

    dependencies {
        repositories {
            google()
            jcenter()
            maven { url "https://jitpack.io" }
        }
    }
}