-
Notifications
You must be signed in to change notification settings - Fork 963
/
run.ts
56 lines (46 loc) · 1.65 KB
/
run.ts
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
import Debug from 'debug';
import { resolve } from 'path';
import c from '../colors';
import { promptForPlatformTarget, runTask } from '../common';
import type { Config } from '../definitions';
import type { RunCommandOptions } from '../tasks/run';
import { runNativeRun, getPlatformTargets } from '../util/native-run';
import { runCommand } from '../util/subprocess';
const debug = Debug('capacitor:android:run');
export async function runAndroid(
config: Config,
{ target: selectedTarget }: RunCommandOptions,
): Promise<void> {
const target = await promptForPlatformTarget(
await getPlatformTargets('android'),
selectedTarget,
);
const arg = `assemble${config.android?.flavor || ''}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) {
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 apkPath = resolve(
config.android.buildOutputDirAbs,
config.android.apkName,
);
const nativeRunArgs = ['android', '--app', apkPath, '--target', target.id];
debug('Invoking native-run with args: %O', nativeRunArgs);
await runTask(
`Deploying ${c.strong(config.android.apkName)} to ${c.input(target.id)}`,
async () => runNativeRun(nativeRunArgs),
);
}