2018-12-11 14:55:06 +01:00
|
|
|
const options = require('commander')
|
|
|
|
|
const spawnSync = require('child_process').spawnSync
|
|
|
|
|
|
2018-12-20 11:35:22 +01:00
|
|
|
/**
|
|
|
|
|
* Besides options below this script may require signing parameters passed as environment variables:
|
|
|
|
|
* 'APK_SIGN_ALIAS'
|
|
|
|
|
* 'APK_SIGN_STORE_PASS'
|
|
|
|
|
* 'APK_SIGN_KEY_PASS'
|
|
|
|
|
* 'APK_SIGN_STORE'
|
|
|
|
|
* 'ANDROID_HOME'
|
|
|
|
|
*/
|
|
|
|
|
|
2018-12-11 14:55:06 +01:00
|
|
|
options
|
|
|
|
|
.usage('[options] [test|prod|URL] ')
|
|
|
|
|
.arguments('<targetUrl>')
|
2018-12-11 15:23:03 +01:00
|
|
|
.option('-b, --buildtype <type>', 'gradle build type', /^(debugDist|debug|release|releaseTest)$/i, 'release')
|
2018-12-11 14:55:06 +01:00
|
|
|
.option('-w --webclient <client>', 'choose web client build', /^(build|dist)$/i, 'dist')
|
|
|
|
|
.parse(process.argv)
|
|
|
|
|
options.host = options.args[0] || 'prod'
|
|
|
|
|
|
2018-12-20 11:35:22 +01:00
|
|
|
console.log(`Starting build with buildtype: ${options.buildtype} webclient: ${options.webclient} host: ${options.host}`)
|
|
|
|
|
|
2018-12-11 14:55:06 +01:00
|
|
|
let apkPath
|
|
|
|
|
|
|
|
|
|
switch (options.buildtype) {
|
|
|
|
|
case 'debugDist':
|
|
|
|
|
apkPath = 'app/build/outputs/apk/debugDist/app-debugDist.apk'
|
|
|
|
|
break;
|
|
|
|
|
case 'debug':
|
|
|
|
|
apkPath = 'app/build/outputs/apk/debug/app-debug.apk'
|
|
|
|
|
break;
|
2018-12-11 15:23:03 +01:00
|
|
|
case 'releaseTest':
|
|
|
|
|
apkPath = 'app/build/outputs/apk/releaseTest/app-releaseTest-unsigned.apk'
|
|
|
|
|
break
|
2018-12-11 14:55:06 +01:00
|
|
|
default:
|
|
|
|
|
apkPath = 'app/build/outputs/apk/release/app-release-unsigned.apk'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {error} = spawnSync('node', [options.webclient, `${options.host}`], {
|
|
|
|
|
stdio: [null, process.stdout, process.stderr]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log("Error during ", options.webclient, error)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("Starting", options.buildtype)
|
|
|
|
|
|
|
|
|
|
error = spawnSync('./gradlew', [`assemble${options.buildtype}`], {
|
|
|
|
|
cwd: './app-android/',
|
|
|
|
|
stdio: [null, process.stdout, process.stderr]
|
|
|
|
|
}).error
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log("Gradle Error:", error)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getEnv = (name) => {
|
|
|
|
|
if (!(name in process.env)) {
|
|
|
|
|
throw new Error(`${name} is not set`)
|
|
|
|
|
}
|
|
|
|
|
return process.env[name]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spawnSync("rm", ["-r", "build/app-android"])
|
|
|
|
|
spawnSync("mkdir", ["-p", "build/app-android"])
|
|
|
|
|
const version = require('./package.json').version
|
|
|
|
|
const outPath = `./build/app-android/tutanota-${version}-${options.buildtype}.apk`
|
|
|
|
|
|
2018-12-11 15:23:03 +01:00
|
|
|
if (options.buildtype === 'release' || options.buildtype === 'releaseTest') {
|
2018-12-11 14:55:06 +01:00
|
|
|
const keyAlias = getEnv('APK_SIGN_ALIAS')
|
|
|
|
|
const storePass = getEnv('APK_SIGN_STORE_PASS')
|
|
|
|
|
const keyPass = getEnv('APK_SIGN_KEY_PASS')
|
|
|
|
|
const keyStore = getEnv('APK_SIGN_STORE')
|
|
|
|
|
const androidHome = getEnv('ANDROID_HOME')
|
|
|
|
|
|
|
|
|
|
console.log("starting signing")
|
2018-12-13 11:46:47 +01:00
|
|
|
// see https://developer.android.com/studio/publish/app-signing#signing-manually
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2018-12-13 11:46:47 +01:00
|
|
|
// jarsigner must be run before zipalign
|
2018-12-11 14:55:06 +01:00
|
|
|
error = spawnSync('jarsigner', [
|
|
|
|
|
'-verbose',
|
|
|
|
|
'-keystore', keyStore,
|
|
|
|
|
'-storepass', storePass,
|
|
|
|
|
'-keypass', keyPass,
|
|
|
|
|
'./app-android/' + apkPath,
|
|
|
|
|
keyAlias
|
|
|
|
|
], {
|
|
|
|
|
stdio: [null, null, process.stderr]
|
|
|
|
|
}).error
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log('Signing Error:', error)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("started zipalign")
|
|
|
|
|
|
2018-12-13 11:46:47 +01:00
|
|
|
// Android requires all resources to be aligned for mmap. Must be done.
|
2018-12-11 14:55:06 +01:00
|
|
|
error = spawnSync(`${androidHome}/build-tools/27.0.3/zipalign`, [
|
|
|
|
|
'4',
|
|
|
|
|
'app-android/' + apkPath,
|
|
|
|
|
outPath
|
|
|
|
|
], {
|
|
|
|
|
stdio: [null, process.stdout, process.stderr]
|
|
|
|
|
}).error
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log("Zipalign Error", error)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
error = spawnSync('mv', ['app-android/' + apkPath, outPath]).error
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.log("mv Error", error.output.toString(), error)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-13 12:49:56 +01:00
|
|
|
console.log(`APK was moved to\n${outPath}`)
|
|
|
|
|
|