MCPcopy
hub / github.com/ionic-team/capacitor / buildAndroid

Function buildAndroid

cli/src/android/build.ts:10–65  ·  view source on GitHub ↗
(config: Config, buildOptions: BuildCommandOptions)

Source from the content-addressed store, hash-verified

8import { runCommand } from '../util/subprocess';
9
10export async function buildAndroid(config: Config, buildOptions: BuildCommandOptions): Promise<void> {
11 const releaseType = buildOptions.androidreleasetype ?? 'AAB';
12 const releaseTypeIsAAB = releaseType === 'AAB';
13 const flavor = buildOptions.flavor ?? '';
14 const arg = releaseTypeIsAAB ? `:app:bundle${flavor}Release` : `assemble${flavor}Release`;
15 const gradleArgs = [arg];
16
17 try {
18 await runTask('Running Gradle build', async () =>
19 runCommand('./gradlew', gradleArgs, {
20 cwd: config.android.platformDirAbs,
21 }),
22 );
23 } catch (e) {
24 if ((e as any).includes('EACCES')) {
25 throw `gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${c.strong(
26 `chmod +x ./${config.android.platformDir}/gradlew`,
27 )} and try again.`;
28 } else {
29 throw e;
30 }
31 }
32
33 const releaseDir = releaseTypeIsAAB
34 ? flavor !== ''
35 ? `${flavor}Release`
36 : 'release'
37 : flavor !== ''
38 ? join(flavor, 'release')
39 : 'release';
40
41 const releasePath = join(
42 config.android.appDirAbs,
43 'build',
44 'outputs',
45 releaseTypeIsAAB ? 'bundle' : 'apk',
46 releaseDir,
47 );
48
49 const unsignedReleaseName = `app${flavor !== '' ? `-${flavor}` : ''}-release${
50 releaseTypeIsAAB ? '' : '-unsigned'
51 }.${releaseType.toLowerCase()}`;
52
53 const signedReleaseName = unsignedReleaseName.replace(
54 `-release${releaseTypeIsAAB ? '' : '-unsigned'}.${releaseType.toLowerCase()}`,
55 `-release-signed.${releaseType.toLowerCase()}`,
56 );
57
58 if (buildOptions.signingtype == 'jarsigner') {
59 await signWithJarSigner(config, buildOptions, releasePath, signedReleaseName, unsignedReleaseName);
60 } else {
61 await signWithApkSigner(config, buildOptions, releasePath, signedReleaseName, unsignedReleaseName);
62 }
63
64 logSuccess(`Successfully generated ${signedReleaseName} at: ${releasePath}`);
65}
66
67async function signWithApkSigner(

Callers 1

buildFunction · 0.90

Calls 5

runTaskFunction · 0.90
runCommandFunction · 0.90
logSuccessFunction · 0.90
signWithJarSignerFunction · 0.85
signWithApkSignerFunction · 0.85

Tested by

no test coverage detected