aboutsummaryrefslogtreecommitdiff
path: root/app/build.gradle
blob: c8d46967812e05a7892e7e6702ca0411afe489a6 (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
apply plugin: 'com.android.application'
//apply plugin: 'com.bugsnag.android.gradle'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
//apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'com.gladed.androidgitversion'


buildscript {
    repositories {
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "com.github.node-gradle:gradle-node-plugin:${Versions.nodeGradle}"
    }
}

apply plugin: 'com.github.node-gradle.node'

apply from: '../spotless.gradle'
group = APP_GROUP

android {
    compileSdkVersion Versions.targetSdk

    androidGitVersion {
        codeFormat = 'MMNNPPXX'
        format = '%tag%%-count%%-commit%'
        prefix 'v'
    }

    defaultConfig {
        applicationId "${project.APP_GROUP}.${project.APP_ID.toLowerCase(Locale.CANADA)}"
        minSdkVersion kau.Versions.minSdk
        targetSdkVersion Versions.targetSdk
//        versionCode 2040500
        versionCode androidGitVersion.code()
//        versionName '2.4.5'
        versionName androidGitVersion.name()

        if (System.getenv('TRAVIS') != 'true') {
            // Verification for F-Droid builds
            if (versionCode != androidGitVersion.code()) {
                throw new GradleException("Version code mismatch, expected ${androidGitVersion.code()}, got $versionCode")
            }
            if (versionName != androidGitVersion.name()) {
                throw new GradleException("Version name mismatch, expected ${androidGitVersion.name()}, got $versionName")
            }
            multiDexEnabled true
            testInstrumentationRunner "com.pitchedapps.frost.FrostTestRunner"
            javaCompileOptions {
                annotationProcessorOptions {
                    arguments = ["room.schemaLocation": "$projectDir/src/schemas".toString()]
                }
            }
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${project.APP_ID}-${variant.buildType.name}.apk"
        }
    }

    lintOptions {
        warningsAsErrors true
        disable 'TrustAllX509TrustManager',
                'UnusedResources',
                'ContentDescription',
                'RtlSymmetry',
                'MissingTranslation'

        xmlReport false
        textReport true
        textOutput 'stdout'
    }

    buildFeatures {
        viewBinding = true
    }

    def testKeystoreFile = file('../files/test.keystore')
    def testPropFile = file('../files/test.properties')
    def withTestSigning = testKeystoreFile.exists() && testPropFile.exists()

    def releaseKeystoreFile = file('../files/release.keystore')
    def releasePropFile = file('../files/release.properties')
    def withReleaseSigning = releaseKeystoreFile.exists() && releasePropFile.exists()

    signingConfigs {

        debug {
            storeFile file("../files/debug.keystore")
            storePassword "debugKey"
            keyAlias "debugKey"
            keyPassword "debugKey"
        }

        if (withTestSigning) {
            def testProps = new Properties()
            testPropFile.withInputStream { testProps.load(it) }

            test {
                storeFile testKeystoreFile
                storePassword testProps.getProperty('storePassword')
                keyAlias testProps.getProperty('keyAlias')
                keyPassword testProps.getProperty('keyPassword')
            }
        }

        if (withReleaseSigning) {
            def releaseProps = new Properties()
            releasePropFile.withInputStream { releaseProps.load(it) }

            release {
                storeFile releaseKeystoreFile
                storePassword releaseProps.getProperty('storePassword')
                keyAlias releaseProps.getProperty('keyAlias')
                keyPassword releaseProps.getProperty('keyPassword')
            }
        }

    }

    def compilerArgs = ["-Xuse-experimental=kotlin.Experimental" /*, "-XXLanguage:+InlineClasses"*/]

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
            signingConfig signingConfigs.debug
            resValue "string", "frost_name", "Frost Debug"
            resValue "string", "frost_web", "Frost Web Debug"
            ext.enableBugsnag = false

            kotlinOptions.freeCompilerArgs += compilerArgs
        }
        releaseTest {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationIdSuffix ".test"
            versionNameSuffix "-test"
            if (withTestSigning) signingConfig signingConfigs.test
            resValue "string", "frost_name", "Frost Test"
            resValue "string", "frost_web", "Frost Web Test"
        }
        release {
            minifyEnabled true
            shrinkResources true
            if (withReleaseSigning) signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            resValue "string", "frost_name", "Frost"
            resValue "string", "frost_web", "Frost Web"
        }
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
        androidTest.java.srcDirs += 'src/androidTest/kotlin'
        main.assets.srcDirs += ['src/web/assets']
    }

    packagingOptions {
        pickFirst 'META-INF/core_release.kotlin_module'
        pickFirst 'META-INF/library_release.kotlin_module'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    testOptions.unitTests {
        includeAndroidResources = true
        // Don't throw runtime exceptions for android calls that are not mocked
        returnDefaultValues = true

        // Always show the result of every unit test, even if it passes.
        all {
            testLogging {
                events 'skipped', 'failed', 'standardError'
            }
        }
    }

    androidExtensions {
        experimental = true
        features = ["parcelize"]
    }

}

node {
    version = '13.8.0'
    npmVersion = '6.13.7'
    download = true
    nodeModulesDir = file("${project.projectDir}/src/web")
}

task npmCi(type: NpmTask) {
    dependsOn npmSetup
    npmCommand = ["ci"]
}

task frostWebGen(type: NpmTask) {
    dependsOn npmCi
    group 'build'
    description 'Generate Frost web assets'
    args = ['run', 'compile']
}

preBuild.dependsOn(frostWebGen)

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

dependencies {
    androidTestImplementation kau.Dependencies.kotlinTest
    androidTestImplementation kau.Dependencies.espresso
    androidTestImplementation kau.Dependencies.testRules
    androidTestImplementation kau.Dependencies.testRunner
    androidTestImplementation kau.Dependencies.kotlinReflect

    testImplementation kau.Dependencies.kotlinTest
    testImplementation kau.Dependencies.kotlinReflect
    testImplementation kau.Dependencies.junit

    implementation kau.Dependencies.kotlin

    //noinspection GradleDependency
    implementation kau.Dependencies.kau('core', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('core-ui', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('adapter', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('fastadapter', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('about', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('colorpicker', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('mediapicker', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('kpref-activity', KAU)
    //noinspection GradleDependency
    implementation kau.Dependencies.kau('searchview', KAU)

    implementation kau.Dependencies.coreKtx
    implementation kau.Dependencies.swipeRefreshLayout

    implementation "androidx.biometric:biometric:${Versions.andxBiometric}"

    implementation kau.Dependencies.koin
    testImplementation kau.Dependencies.koinTest
    androidTestImplementation kau.Dependencies.koinTest

    implementation kau.Dependencies.coroutines

    implementation "org.apache.commons:commons-text:${Versions.apacheCommonsText}"

    implementation "com.devbrackets.android:exomedia:${Versions.exoMedia}"

    implementation kau.Dependencies.fastAdapter("diff")
    implementation kau.Dependencies.fastAdapter("drag")
    implementation kau.Dependencies.fastAdapter("expandable")

    //noinspection GradleDependency
    implementation kau.Dependencies.glide
    //noinspection GradleDependency
    kapt kau.Dependencies.glideKapt

    debugImplementation kau.Dependencies.leakCanary

    //Icons
    implementation kau.Dependencies.iconicsMaterial
    implementation kau.Dependencies.iconicsCommunity

    implementation kau.Dependencies.materialDialog("input")

    implementation "org.jsoup:jsoup:${Versions.jsoup}"

    implementation "com.squareup.okhttp3:okhttp:${Versions.okhttp}"
    implementation "com.squareup.okhttp3:logging-interceptor:${Versions.okhttp}"
    testImplementation "com.squareup.okhttp3:mockwebserver:${Versions.okhttp}"
    androidTestImplementation "com.squareup.okhttp3:mockwebserver:${Versions.okhttp}"

    implementation kau.Dependencies.bugsnag

    implementation "com.davemorrissey.labs:subsampling-scale-image-view:${Versions.scaleImageView}"

    implementation "androidx.room:room-ktx:${Versions.room}"
    implementation "androidx.room:room-runtime:${Versions.room}"
    kapt "androidx.room:room-compiler:${Versions.room}"
    testImplementation "androidx.room:room-testing:${Versions.room}"

}

def kotlinResolutions = ['kotlin-reflect',
                         'kotlin-stdlib',
                         'kotlin-stdlib-jdk7',
                         'kotlin-stdlib-jdk8',
                         'kotlin-test',
                         'kotlin-test-junit4',
                         'kotlin-test-junit5']

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'org.jetbrains.kotlin' && requested.name in kotlinResolutions) {
            details.useVersion kau.Versions.kotlin
        }
    }
}

task lintGithubReleaseApk {
    dependsOn 'spotlessCheck'
    dependsOn 'lintRelease'
}

task testGithubReleaseApk {
    dependsOn 'testReleaseUnitTest'
    dependsOn 'connectedAndroidTest'
}

task assembleGithubReleaseApk {
    dependsOn 'assembleRelease'
}

// Validates code and generates apk
// TODO order tasks; though technically it doesn't matter
task createGithubReleaseApk {
    dependsOn 'lintGithubReleaseApk'
    dependsOn 'testGithubReleaseApk'
    dependsOn 'assembleGithubReleaseApk'

    tasks.findByName('testGithubReleaseApk').mustRunAfter 'lintGithubReleaseApk'
    tasks.findByName('assembleGithubReleaseApk').mustRunAfter 'testGithubReleaseApk'
}