You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

300 lines
11 KiB

/*
* 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()]
}
}
}
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'
}
}
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", "\"308201a2300d06092a864886f70d01010105000382018f003082018a0282018100d59576eed22e155181773744377501773ac7914709ec7cf24989bc7c1ddff6589ca34ba4aff964becadf0069ec0977079e89aefc0307b6cb187416f529294ffc1b7a06f1fd21bf1c5acc9e3524f834a733fb76fdc6134c78051860788c8753c12d6b5a853a493408ceeb8c222981b6299a2a03e657e0a2dec3db84a40460886c9ca386c7e88513b0980cb06f70862b74adbb38273dce72a7a325f163035dc7a007f9ae042f77c2404c605d4ee9eddf660f0463e99eb44e57edc78aeb3c70005431c87f4413907d9cc3fd946cc819a4e34c451db08325701ab1f78d4506e162a5ccfbfe85a61af06eb2aeb9d2264a42974bf9ba9bff2d5ed4b214cb6aaa30f25011252af2999bffd499e3b6a1a1b979d41dacaa6c9309fd97757c0dac100300ef699ec710800513e3ecc3fbc87f4af14fa9cc459b43b7cc5eef48b3dcc33feba89bd536ca04f1370fd172506fd337edf0a4bba61f625e3e6c757c8e101b1bc99091af40de0782bec8efd629b8a4ec8b264421b44c5db41c4ffa76553a84d5d79b0203010001\""
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'
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
println '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 = 1
def versionMinor = 2
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}(BTC-Only)"
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 {}
}
}
}
}