-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathbuild.gradle
180 lines (163 loc) · 6.55 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
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
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
// See https://developer.android.com/studio/publish/app-signing#secure-shared-keystore
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
try {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
} catch (Exception ex) {
logger.warn("No keys. Release disabled: $ex.message")
keystoreProperties['keyAlias'] = ''
keystoreProperties['keyPassword'] = ''
keystoreProperties['storeFile'] = '/dev/null'
keystoreProperties['storePassword'] = ''
}
// Go backend build constants
def goSourceDir = "${projectDir}/src/go"
def goSourcePackages = ["${goSourceDir}/backend",
"${goSourceDir}/intra",
"${goSourceDir}/intra/split",
"${goSourceDir}/intra/protect"]
def goBuildDir = file("${buildDir}/go")
def goBackendAAR = file("${goBuildDir}/backend.aar")
// gomobile won't use the Go version in go.mod. So we need to manually read it from go.mod and
// explicitly set the GOTOOLCHAIN environment variable later.
def goModLines = new File("${rootDir}/../go.mod").readLines()
def goToolchain = goModLines.find { it.startsWith('toolchain ') }
if (goToolchain == null) {
goToolchain = goModLines.find { it.startsWith('go ') }
if (goToolchain == null) {
throw new GradleException('cannot locate Go toolchain version in go.mod')
}
}
// goToolchain: ['toolchain go1.x.y' or 'go 1.x.y'] -> 'go1.x.y'
goToolchain = goToolchain.replace("toolchain", "").replace(" ", "")
println "using Go toolchain ${goToolchain}"
// Standard Android build definition
android {
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
compileSdkVersion ANDROID_COMPILE_SDK_VERSION as int
buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
applicationId "app.intra"
// Firebase Crashlytics requires SDK version 16.
minSdkVersion ANDROID_MIN_SDK_VERSION as int
targetSdkVersion ANDROID_TARGET_SDK_VERSION as int
versionCode 67
versionName "1.3.9"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
lintOptions {
// Ignore lint errors that we believe are safe to ignore.
baseline file("lint-baseline.xml")
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
signingConfig signingConfigs.config
resValue("bool", "FIREBASE_ENABLED", "true")
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
}
}
debug {
pseudoLocalesEnabled true
resValue("bool", "FIREBASE_ENABLED", "false")
// Split build across multiple dex files. This is necessary mostly because Guava adds
// so many classes that we exceed the dex limit (65536 methods). This does not apply
// to release builds, where unused classes are pruned.
multiDexEnabled true
}
}
testOptions {
unitTests.returnDefaultValues = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
maven {
url 'test-repo'
}
maven {
url '../gradle-plugin-repo'
}
maven {
url '../firebase-repo'
}
}
dependencies {
implementation 'com.google.guava:guava:31.0.1-android'
// Third-party test dependencies.
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.json:json:20180813'
testImplementation 'org.mockito:mockito-core:2.13.0'
// Required for instrumented tests
androidTestImplementation 'androidx.annotation:annotation:1.3.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
// UI libraries.
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation "androidx.viewpager2:viewpager2:1.0.0"
// For Firebase Analytics, etc.
implementation 'com.google.firebase:firebase-analytics:19.0.2' // Last version for API <19
implementation 'com.google.firebase:firebase-perf:20.0.4'
implementation 'com.google.firebase:firebase-crashlytics:18.2.6'
implementation 'com.google.firebase:firebase-crashlytics-ndk:18.2.6'
implementation 'com.google.firebase:firebase-config:21.0.1'
// Go backend (use fileTree instead of files to prevent Android Studio sync errors)
implementation fileTree(goBuildDir) {
include '*.aar'
builtBy 'compileGoBackend'
}
}
// For Firebase Analytics
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
// Go backend build tasks
tasks.register('compileGoBackend', Exec) {
dependsOn 'ensureGoMobile'
// invoke gomobile to compile backend code
inputs.dir(goSourceDir)
outputs.file(goBackendAAR)
environment 'GOTOOLCHAIN', goToolchain
environment 'ANDROID_HOME', android.sdkDirectory
environment 'PATH', goBuildDir.getPath() +
System.getProperty('path.separator') +
System.getenv('PATH')
commandLine("${goBuildDir}/gomobile", 'bind',
'-ldflags=-s -w',
'-target=android',
"-androidapi=${android.defaultConfig.minSdk}",
'-o', goBackendAAR,
*goSourcePackages)
}
tasks.register('ensureGoMobile', Exec) {
// install gomobile and gobind into the build folder
outputs.file("${goBuildDir}/gomobile")
outputs.file("${goBuildDir}/gobind")
doFirst { goBuildDir.mkdirs() }
environment 'GOTOOLCHAIN', goToolchain
commandLine('go', 'build',
'-o', goBuildDir,
'golang.org/x/mobile/cmd/gomobile',
'golang.org/x/mobile/cmd/gobind')
}