-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.gradle
314 lines (275 loc) · 11.1 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
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
/*
* Copyright (c) 2020 Cobo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
*/
import groovy.xml.XmlUtil
import java.security.MessageDigest
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = true
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
def (mIsVaultRelease, mVersionNumber, mVersionName) = getVersionProperties()
println("start to build ${mVersionName}")
println("start to build ${getGitHash()}")
defaultConfig {
applicationId "com.cobo.cold"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode mVersionNumber
versionName mVersionName
ndk {
abiFilters "armeabi-v7a"
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
resConfigs "en", "zh-rCN"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
dataBinding {
enabled = true
}
signingConfigs {
vault_v2 {
def key = getReleaseKeystore()
storeFile key.store
storePassword key.storePassword
keyAlias key.alias
keyPassword key.keyPassword
}
}
buildTypes {
release {
debuggable false
minifyEnabled enableProguardInReleaseBuilds
shrinkResources enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile('proguard-android.txt')
proguardFiles 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/ASL-2.0.txt'
pickFirst 'draftv4/schema'
pickFirst 'draftv3/schema'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LGPL-3.0.txt'
exclude 'tables/**'
exclude '**/*.proto'
exclude 'org/**'
exclude '**/*.txt'
exclude 'jni/**'
exclude 'solidity/**'
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
flavorDimensions 'machine'
productFlavors {
vault_v2 {
dimension 'machine'
ndk {
abiFilters "armeabi-v7a"
}
manifestPlaceholders = ["sharedUserId": 'android.uid.system']
buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\""
buildConfigField "String", "UPDATE_PUBLIC_KEY", "\"308201a2300d06092a864886f70d01010105000382018f003082018a0282018100df75e9c2f82e9113e93cf5cf1739436694f12b9009c6bc37156f3cc30f259f3a0661bdd223a833d39a468161751c58a870f25022c619a4010b49058ae23c2b67dab4d6e3cb92a119a0de326303dbad67b33c79a8a1643db6f1a5e955bc7d4de6e9080780df37ac0bc8ad32e9b013e467f04bf0ab158059f5bd728b822456b728b7ec0ba894433f309a7f17fda5df463b09ecc8af5dfbb1159127aaee393696bfb5291353522a5428897824904f25f0b61453d295fd920303e2f72928e17212cbb11d0c701e13029761c570cc46c6fa1ddbbc973864595d860ebbca03bdb9e70136f09210e94e614df988a2dac7bfcc9acb997ed01ab4f75cbf02336c6a753a4ec6b517e0ec84f260d61a4e00ee56d9e152bd8b9a2f0a48846993bd95e2db308c23aedc2e527b532228661c6fb63e2b0dd0900b2a1a36a6d046d64a3a59fef9c566771fd541b5cdb074effd02574a6b5eaa1194e8fc1f2f835657ac9a72a20412e446b3a47105ee65745e6b816b906ef34545fe6fb4aaadc37703e6f599dc6d370203010001\""
signingConfig signingConfigs.vault_v2
}
}
if (mIsVaultRelease) {
afterEvaluate {
task copyRelease(type: Copy) {
from "${buildDir}/outputs/apk/vault_v2/release"
into "${rootDir}/releases/${mVersionNumber}"
include '*.apk'
}
task archiveMapping(type: Zip) {
from "${buildDir}/outputs/mapping/vault_v2/release"
destinationDir file("${rootDir}/releases/${mVersionNumber}")
include '*'
archiveName "mapping_${mVersionNumber}.zip"
}
assembleVault_v2Release.finalizedBy(copyRelease, archiveMapping)
}
this.gradle.buildFinished {
def apkPath = "${rootDir}/releases/${mVersionNumber}/app-vault_v2-release.apk"
def apk = file(apkPath)
exec {
commandLine 'mv', apkPath,
"${rootDir}/releases/${mVersionNumber}/app_${mVersionNumber}_V${mVersionName}_${getGitHash()}_${calcSha1(apk)}.apk"
}
}
}
sourceSets {
main {
proto {
srcDir 'src/main/protos'
}
}
}
}
dependencies {
compileOnly files('libs/cvos.jar')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.2.0-rc04'
implementation 'androidx.navigation:navigation-ui:2.2.0-rc04'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.room:room-runtime:2.1.0'
implementation "androidx.preference:preference:1.1.0"
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.protobuf:protobuf-java:3.7.1'
implementation 'com.google.zxing:core:3.3.3'
implementation 'com.googlecode.protobuf-java-format:protobuf-java-format:1.4'
implementation 'com.madgag.spongycastle:core:1.58.0.0@jar'
implementation 'com.yanzhenjie:permission:2.0.0-rc4'
implementation 'cn.carbswang.android:NumberPickerView:1.2.0'
implementation 'com.andrognito.patternlockview:patternlockview:1.0.0'
implementation 'com.allenliu.badgeview:library:1.1.1'
implementation 'net.lingala.zip4j:zip4j:1.3.2@jar'
implementation 'com.wei.android.lib:fingerprintidentify:1.2.6'
implementation 'com.github.donkingliang:ConsecutiveScroller:2.5.0'
implementation 'com.github.CoboVault:bc32-java:v0.0.6-alpha'
implementation 'com.github.CoboVault:shamir-secret:0.03-alpha'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
implementation project(':encryption-core')
implementation project(path: ':coinlib')
testImplementation 'junit:junit:4.12'
testImplementation 'org.json:json:20140107'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'junit:junit:4.12'
}
preBuild {
doLast {
def imlFile = file(project.name + ".iml")
println 'Change ' + project.name + '.iml order'
try {
def parsedXml = (new XmlParser()).parse(imlFile)
def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
parsedXml.component[1].remove(jdkNode)
def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
//noinspection GroovyResultOfObjectAllocationIgnored
new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
} catch (FileNotFoundException ignored) {
// nop, iml not found
}
}
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
def getVersionProperties() {
def versionPropsFile = file('version.properties')
def versionProps = new Properties()
if (versionPropsFile.exists()) {
if (versionPropsFile.canRead()) {
versionProps.load(new FileInputStream(versionPropsFile))
} else {
throw new GradleException("could not read version.properties!")
}
}
def versionMajor = versionProps.getProperty('major', '0').toInteger()
def versionMinor = versionProps.getProperty('minor', '0').toInteger()
def versionPatch = versionProps.getProperty('patch', '0').toInteger()
def isVaultRelease = false
gradle.startParameter.taskNames.each {
if (it.contains("assembleVaultRelease") || it.contains("assembleVault_v2Release")) {
isVaultRelease = true
return
}
}
def versionNumber = versionMajor * 10000 + versionMinor * 100 + versionPatch
def versionName = "${versionMajor}.${versionMinor}.${versionPatch}"
return [isVaultRelease, versionNumber, versionName]
}
def getReleaseKeystore() {
def keystoreDir = new File(rootDir, "keystores")
if (!keystoreDir.exists()) {
throw new FileNotFoundException("could not find ${keystoreDir}")
}
def keystorePropsFile = new File(keystoreDir, "test.properties")
if (!keystorePropsFile.exists()) {
throw new FileNotFoundException("could not find ${keystorePropsFile}")
}
def keystoreProps = new Properties()
keystoreProps.load(new FileInputStream(keystorePropsFile))
def keystoreFile = new File(keystoreDir, keystoreProps['key.store'])
if (!keystoreFile.exists()) {
throw new FileNotFoundException("could not find ${keystoreFile}")
}
return [
store : keystoreFile,
alias : keystoreProps['key.alias'],
storePassword: keystoreProps['key.store.password'],
keyPassword : keystoreProps['key.alias.password']
].asImmutable()
}
def getGitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short=40', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
static def calcSha1(file) {
MessageDigest md = MessageDigest.getInstance("SHA-1")
file.eachByte 4096, { bytes, size ->
md.update(bytes, 0, size)
}
return md.digest().collect { String.format "%02x", it }.join()
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.7.1'
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.builtins {
java {}
}
}
}
}