tutanota/android.js

110 lines
3 KiB
JavaScript
Raw Normal View History

2018-12-11 14:55:06 +01:00
const options = require('commander')
2019-02-01 11:42:51 +01:00
const {execFileSync} = require('child_process')
2018-12-11 14:55:06 +01:00
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>')
.option('-b, --buildtype <type>', 'gradle build type', /^(debugDist|debug|release|releaseTest)$/i, 'release')
2019-02-27 11:16:51 +01:00
.option('-w --webclient <client>', 'choose web client build', /^(make|dist)$/i, 'dist')
2018-12-11 14:55:06 +01:00
.parse(process.argv)
options.host = options.args[0] || 'prod'
const BUILD_TOOLS_V = "28.0.3"
2019-02-01 11:42:51 +01:00
const log = (...messages) => console.log("\nBUILD: ", ...messages, "\n")
log(`Starting build with buildtype: ${options.buildtype}, webclient: ${options.webclient}, host: ${options.host}`)
2018-12-20 11:35:22 +01:00
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;
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'
}
2019-02-01 11:42:51 +01:00
execFileSync('node', [options.webclient, `${options.host}`], {
2018-12-11 14:55:06 +01:00
stdio: [null, process.stdout, process.stderr]
2019-02-01 11:42:51 +01:00
})
execFileSync('node', ["buildSrc/prepareMobileBuild.js", options.webclient], {
stdio: [null, process.stdout, process.stderr],
})
2018-12-11 14:55:06 +01:00
2019-02-01 11:42:51 +01:00
try {
execFileSync("rm", ["-r", "build/app-android"], {stdio: 'ignore'})
} catch (e) {
// Ignoring the error if the folder is not there
2018-12-11 14:55:06 +01:00
}
2019-02-01 11:42:51 +01:00
log("Starting", options.buildtype)
2018-12-11 14:55:06 +01:00
2019-02-01 11:42:51 +01:00
execFileSync('./gradlew', [`assemble${options.buildtype}`], {
2018-12-11 14:55:06 +01:00
cwd: './app-android/',
2019-02-01 11:42:51 +01:00
})
2018-12-11 14:55:06 +01:00
const getEnv = (name) => {
if (!(name in process.env)) {
throw new Error(`${name} is not set`)
}
return process.env[name]
}
2019-02-01 11:42:51 +01:00
execFileSync("mkdir", ["-p", "build/app-android"])
2018-12-11 14:55:06 +01:00
const version = require('./package.json').version
const outPath = `./build/app-android/tutanota-${version}-${options.buildtype}.apk`
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')
2019-02-01 11:42:51 +01:00
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
2019-07-17 11:10:37 +02:00
execFileSync('/opt/jdk1.8.0_112/bin/jarsigner', [
2018-12-11 14:55:06 +01:00
'-verbose',
'-strict',
2018-12-11 14:55:06 +01:00
'-keystore', keyStore,
'-storepass', storePass,
'-keypass', keyPass,
'./app-android/' + apkPath,
keyAlias
2019-02-01 11:42:51 +01:00
])
2018-12-11 14:55:06 +01:00
2019-02-01 11:42:51 +01:00
log("started zipalign")
2018-12-11 14:55:06 +01:00
2018-12-13 11:46:47 +01:00
// Android requires all resources to be aligned for mmap. Must be done.
2019-02-01 11:42:51 +01:00
execFileSync(`${androidHome}/build-tools/${BUILD_TOOLS_V}/zipalign`, [
2018-12-11 14:55:06 +01:00
'4',
'app-android/' + apkPath,
outPath
2019-02-01 11:42:51 +01:00
])
2018-12-11 14:55:06 +01:00
} else {
2019-02-01 11:42:51 +01:00
execFileSync('mv', ['app-android/' + apkPath, outPath])
2018-12-11 14:55:06 +01:00
}
2019-02-01 11:42:51 +01:00
log(`APK was moved to\n${outPath}`)
2018-12-13 12:49:56 +01:00