forked from ionic-team/capacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ts
More file actions
69 lines (56 loc) · 2.19 KB
/
run.ts
File metadata and controls
69 lines (56 loc) · 2.19 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
import Debug from 'debug';
import { resolve } from 'path';
import c from '../colors.js';
import { parseApkNameFromFlavor, promptForPlatformTarget, runTask } from '../common.js';
import type { Config } from '../definitions.js';
import type { RunCommandOptions } from '../tasks/run.js';
import { runNativeRun, getPlatformTargets } from '../util/native-run.js';
import { runCommand } from '../util/subprocess.js';
const debug = Debug('capacitor:android:run');
export async function runAndroid(
config: Config,
{
target: selectedTarget,
targetName: selectedTargetName,
targetNameSdkVersion: selectedTargetSdkVersion,
flavor: selectedFlavor,
forwardPorts: selectedPorts,
}: RunCommandOptions,
): Promise<void> {
const target = await promptForPlatformTarget(
await getPlatformTargets('android'),
selectedTarget ?? selectedTargetName,
selectedTargetSdkVersion,
selectedTargetName !== undefined,
);
const runFlavor = selectedFlavor || config.android?.flavor || '';
const arg = `assemble${runFlavor}Debug`;
const gradleArgs = [arg];
debug('Invoking ./gradlew with args: %O', gradleArgs);
try {
await runTask('Running Gradle build', async () =>
runCommand('./gradlew', gradleArgs, {
cwd: config.android.platformDirAbs,
}),
);
} catch (e: any) {
if (e.includes('EACCES')) {
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(
`chmod +x ./${config.android.platformDir}/gradlew`,
)} and try again.`;
} else {
throw e;
}
}
const pathToApk = `${config.android.platformDirAbs}/${
config.android.appDir
}/build/outputs/apk${runFlavor !== '' ? '/' + runFlavor : ''}/debug`;
const apkName = parseApkNameFromFlavor(runFlavor);
const apkPath = resolve(pathToApk, apkName);
const nativeRunArgs = ['android', '--app', apkPath, '--target', target.id];
if (selectedPorts) {
nativeRunArgs.push('--forward', `${selectedPorts}`);
}
debug('Invoking native-run with args: %O', nativeRunArgs);
await runTask(`Deploying ${c.strong(apkName)} to ${c.input(target.id)}`, async () => runNativeRun(nativeRunArgs));
}