-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathandroid.js
More file actions
183 lines (151 loc) · 5.62 KB
/
android.js
File metadata and controls
183 lines (151 loc) · 5.62 KB
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
/**
* Build script for android app.
*
* 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'
*/
import { Argument, Option, program } from "commander"
import { runDevBuild } from "./buildSrc/DevBuild.js"
import { prepareMobileBuild } from "./buildSrc/prepareMobileBuild.js"
import { buildWebapp } from "./buildSrc/buildWebapp.js"
import { getTutanotaAppVersion, measure } from "./buildSrc/buildUtils.js"
import path from "node:path"
import { $, cd } from "zx"
const log = (...messages) => console.log(chalk.green("\nBUILD:"), ...messages, "\n")
await program
.usage("[options] [test|prod|local|host <url>] ")
.addArgument(
new Argument("stage", "the server to connect to. test/local/prod are shorthands for using host <url> of the corresponding staging level server")
.choices(["test", "prod", "local", "host"])
.default("prod")
.argOptional(),
)
.addArgument(new Argument("host").argOptional())
.addOption(new Option("-a, --app <type>", "app to build").choices(["mail", "calendar"]).default("mail"))
.addOption(
new Option(
"-b, --buildtype <type>",
"gradle build type. use debug if you need to debug the app with android studio. release and releaseTest build the same app with different appIds for side-by-side installation",
)
.choices(["debug", "release", "releaseTest"])
.default("release"),
)
.addOption(new Option("-i, --install", "call adb install after build to deploy the app to a device/emulator"))
.addOption(
new Option(
"-w --webclient <client>",
"choose web client build. make is faster and easier to debug, but dist is what would be running in production. There's usually no reason to use dist during development.",
)
.choices(["make", "dist"])
.default("dist"),
)
.option("-e, --existing", "Use existing prebuilt web client files to skip the lengthy web client build. Use if you're developing the Kotlin code.")
.action(async (stage, host, { webclient, buildtype, install, existing, app }) => {
if ((stage === "host" && host == null) || (stage !== "host" && host != null)) {
program.outputHelp()
process.exit(1)
}
const apk = await buildAndroid({
stage: stage ?? "prod",
host: host,
webClient: webclient,
existing,
buildType: buildtype,
app,
})
if (install) {
await $`adb install ${apk}`
// would be cool to auto-start the app, but needs to figure out the correct app to start:
// await $`adb shell am start -n de.tutao.tutanota/de.tutao.tutanota.MainActivity`
}
})
.parseAsync(process.argv)
async function buildCalendarBundle({ buildType }) {
const { version } = JSON.parse(await $`cat package.json`.quiet())
const bundleName = `calendar-tutao-${buildType}-${version}.aab`
const bundlePath = `app-android/calendar/build/outputs/bundle/tutao${buildType.charAt(0).toUpperCase() + buildType.slice(1)}/${bundleName}`
const outPath = `./build-calendar-app/app-android/${bundleName}`
cd("./app-android")
await $`./gradlew :calendar:bundleTutao${buildType}`
cd("..")
await $`mkdir -p build-calendar-app/app-android`
await $`mv ${bundlePath} ${outPath}`
log(`Build complete. The AAB is located at: ${outPath}`)
return outPath
}
async function buildCalendarApk({ buildType }) {
const { version } = JSON.parse(await $`cat package.json`.quiet())
const bundleName = `calendar-tutao-${buildType}-${version}`
const bundlePath = `app-android/calendar/build/outputs/apk/tutao/${buildType}/${bundleName}`
const outPath = `./build-calendar-app/app-android/${bundleName}`
cd("./app-android")
await $`if [ -f .${outPath}.aab ]; then mkdir ../temp; mv .${outPath}.aab ../temp/${bundleName}.aab; fi`
await $`./gradlew :calendar:assembleTutao${buildType}`
cd("..")
await $`mkdir -p build-calendar-app/app-android`
await $`mv ${bundlePath}.apk ${outPath}.apk`
await $`if [ -f ./temp/${bundleName}.aab ]; then mv ./temp/${bundleName}.aab ${outPath}.aab; rm -d ./temp; fi`
log(`Build complete. The APK is located at: ${outPath}`)
return outPath
}
async function buildMailApk({ buildType }) {
const { version } = JSON.parse(await $`cat package.json`.quiet())
const apkName = `tutanota-app-tutao-${buildType}-${version}.apk`
const apkPath = `app-android/app/build/outputs/apk/tutao/${buildType}/${apkName}`
const outPath = `./build/app-android/${apkName}`
cd("./app-android")
await $`./gradlew :app:assembleTutao${buildType}`
cd("..")
await $`mkdir -p build/app-android`
await $`mv ${apkPath} ${outPath}`
log(`Build complete. The APK is located at: ${outPath}`)
return outPath
}
async function buildAndroid({ stage, host, buildType, existing, webClient, app }) {
log(`Starting ${stage} build with build type: ${buildType}, webclient: ${webClient}, host: ${host}`)
if (!existing) {
if (webClient === "make") {
await runDevBuild({
stage,
host,
desktop: false,
clean: false,
watch: false,
serve: false,
networkDebugging: false,
app,
})
} else {
const version = await getTutanotaAppVersion()
await buildWebapp({
version,
stage,
host,
minify: true,
projectDir: path.resolve("."),
measure,
app,
mobileBuild: true,
})
}
} else {
console.log("skipped webapp build")
}
await prepareMobileBuild({ app })
const buildDir = app === "mail" ? "build" : "build-calendar-app"
try {
await $`rm -r ${buildDir}/app-android`
} catch (e) {
// Ignoring the error if the folder is not there
}
if (app === "mail") {
return await buildMailApk({ buildType })
} else {
await buildCalendarBundle({ buildType })
return await buildCalendarApk({ buildType })
}
}