2021-01-29 10:38:21 +01:00
|
|
|
import options from "commander"
|
|
|
|
|
|
|
|
import {execFileSync} from "child_process"
|
|
|
|
import {prepareFiles} from "./buildSrc/prepareMobileBuild.js"
|
|
|
|
import fs from "fs"
|
|
|
|
|
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>')
|
2018-12-11 15:23:03 +01:00
|
|
|
.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'
|
|
|
|
|
2020-02-07 15:44:03 +01:00
|
|
|
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;
|
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'
|
|
|
|
}
|
|
|
|
|
2021-06-18 11:10:33 +02:00
|
|
|
exec('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
|
|
|
})
|
|
|
|
|
2021-01-29 10:38:21 +01:00
|
|
|
// execFileSync('node', ["buildSrc/prepareMobileBuild.js", options.webclient], {
|
|
|
|
// stdio: [null, process.stdout, process.stderr],
|
|
|
|
// })
|
2019-07-08 11:47:35 +02:00
|
|
|
|
2021-01-29 10:38:21 +01:00
|
|
|
prepareFiles(options.webclient)
|
2018-12-11 14:55:06 +01:00
|
|
|
|
2019-02-01 11:42:51 +01:00
|
|
|
try {
|
2021-06-18 11:10:33 +02:00
|
|
|
exec("rm", ["-r", "build/app-android"], {stdio: 'ignore'})
|
2019-02-01 11:42:51 +01:00
|
|
|
} 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
|
|
|
|
2021-06-18 11:10:33 +02:00
|
|
|
exec('./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]
|
|
|
|
}
|
|
|
|
|
2021-01-29 10:38:21 +01:00
|
|
|
signAndroidApp()
|
2021-06-18 11:10:33 +02:00
|
|
|
.catch(e => {
|
|
|
|
console.error("Error:", e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2021-01-29 10:38:21 +01:00
|
|
|
|
|
|
|
async function signAndroidApp() {
|
|
|
|
const {version} = JSON.parse(await fs.promises.readFile("package.json", "utf8"))
|
2021-06-18 11:10:33 +02:00
|
|
|
exec("mkdir", ["-p", "build/app-android"])
|
2021-01-29 10:38:21 +01:00
|
|
|
const outPath = `./build/app-android/tutanota-${version}-${options.buildtype}.apk`
|
|
|
|
|
|
|
|
if (options.buildtype === 'release' || options.buildtype === 'releaseTest') {
|
|
|
|
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')
|
|
|
|
|
|
|
|
log("starting signing")
|
|
|
|
// see https://developer.android.com/studio/publish/app-signing#signing-manually
|
|
|
|
|
|
|
|
// jarsigner must be run before zipalign
|
2021-06-18 11:10:33 +02:00
|
|
|
exec('/opt/jdk1.8.0_112/bin/jarsigner', [
|
2021-01-29 10:38:21 +01:00
|
|
|
'-verbose',
|
|
|
|
'-strict',
|
|
|
|
'-keystore', keyStore,
|
|
|
|
'-storepass', storePass,
|
|
|
|
'-keypass', keyPass,
|
|
|
|
'./app-android/' + apkPath,
|
|
|
|
keyAlias
|
|
|
|
])
|
|
|
|
|
|
|
|
log("started zipalign")
|
|
|
|
|
|
|
|
// Android requires all resources to be aligned for mmap. Must be done.
|
2021-06-18 11:10:33 +02:00
|
|
|
exec(`${androidHome}/build-tools/${BUILD_TOOLS_V}/zipalign`, [
|
2021-01-29 10:38:21 +01:00
|
|
|
'4',
|
|
|
|
'app-android/' + apkPath,
|
|
|
|
outPath
|
|
|
|
])
|
|
|
|
} else {
|
2021-06-18 11:10:33 +02:00
|
|
|
exec('mv', ['app-android/' + apkPath, outPath])
|
2021-01-29 10:38:21 +01:00
|
|
|
}
|
|
|
|
log(`APK was moved to\n${outPath}`)
|
2018-12-11 14:55:06 +01:00
|
|
|
}
|
2021-06-18 11:10:33 +02:00
|
|
|
|
|
|
|
function exec(...args) {
|
|
|
|
try {
|
|
|
|
return execFileSync(...args)
|
|
|
|
} catch (e) {
|
|
|
|
throw {
|
|
|
|
code: e.status,
|
|
|
|
stdout: new Buffer(e.stdout).toString(),
|
|
|
|
stderr: new Buffer(e.stderr).toString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|