forked from WorldHealthOrganization/app
/
build.gradle
131 lines (115 loc) · 5.3 KB
/
build.gradle
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
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
} else {
throw new FileNotFoundException('local.properties not found, ensure app is built via Flutter')
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException('Flutter SDK not found. Define location with flutter.sdk in the local.properties file.')
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
def flutterVersionName = localProperties.getProperty('flutter.versionName')
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
// Crashlytics
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId 'org.who.WHOMyHealth'
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
flavorDimensions 'server'
// "hack", "prod" and "staging" flavors, based on:
// https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b
productFlavors {
hack {
dimension 'server'
versionNameSuffix '-hack'
}
prod {
dimension 'server'
}
staging {
dimension 'server'
versionNameSuffix '-staging'
getIsDefault().set(true) // Default Flavor
}
}
// Bundle and Apk copied to expected location for all variants
// TODO: remove once fixed: https://github.com/flutter/flutter/issues/65264
// Based on: https://github.com/flutter/flutter/issues/65264#issuecomment-707013948
applicationVariants.all { variant ->
variant.outputs.all {
def taskSuffix = variant.name.capitalize()
def bundleTaskName = "bundle${taskSuffix}"
if (tasks.findByName(bundleTaskName)) {
def copyAABTask = tasks.create(name: "copyAndRenameAab${taskSuffix}", type: Copy) {
// Cmd: flutter build appbundle --release --flavor prod
// Depends: bundleProdRelease
// Task: copyAndRenameAabProdRelease
// Src: build/app/outputs/bundle/prodRelease/app-prod-release.aab
// Dst: build/app/outputs/bundle/release/app.aab
def bundleBuildDir = "${buildDir}/outputs/bundle"
def originalDirPath = "${variant.productFlavors.name.join()}${variant.buildType.name}"
def originalFileName = "${project.archivesBaseName}-${variant.productFlavors.name.join('-')}-${variant.buildType.name}.aab"
from "${bundleBuildDir}/${originalDirPath}/${originalFileName}"
into "${bundleBuildDir}/${variant.buildType.name}/"
rename ("${originalFileName}", "app.aab")
}
tasks[bundleTaskName].finalizedBy = [copyAABTask]
}
def apkTaskName = "assemble${taskSuffix}"
if (tasks.findByName(apkTaskName)) {
def copyApkTask = tasks.create(name: "copyAndRenameApk${taskSuffix}", type: Copy) {
// Cmd: flutter build apk --flavor prod --release
// Depends: assembleProdRelease (builds the apk)
// Task: copyAndRenameApkProdRelease
// Src: build/app/outputs/apk/prod/release/app-prod-release.apk
// Dst: build/app/outputs/apk/release/app-release.apk
def bundleBuildDir = "${buildDir}/outputs/apk"
def originalDirPath = "${variant.productFlavors.name.join()}/${variant.buildType.name}"
def originalFileName = "${project.archivesBaseName}-${variant.productFlavors.name.join('-')}-${variant.buildType.name}.apk"
from "${bundleBuildDir}/${originalDirPath}/${originalFileName}"
into "${bundleBuildDir}/${variant.buildType.name}/"
rename ("${originalFileName}", "app-${variant.buildType.name}.apk")
}
tasks[apkTaskName].finalizedBy = [copyApkTask]
}
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.multidex:multidex:2.0.1'
}