(
config: Config,
{
target: selectedTarget,
targetName: selectedTargetName,
targetNameSdkVersion: selectedTargetSdkVersion,
flavor: selectedFlavor,
forwardPorts: selectedPorts,
}: RunCommandOptions,
)
| 11 | const debug = Debug('capacitor:android:run'); |
| 12 | |
| 13 | export async function runAndroid( |
| 14 | config: Config, |
| 15 | { |
| 16 | target: selectedTarget, |
| 17 | targetName: selectedTargetName, |
| 18 | targetNameSdkVersion: selectedTargetSdkVersion, |
| 19 | flavor: selectedFlavor, |
| 20 | forwardPorts: selectedPorts, |
| 21 | }: RunCommandOptions, |
| 22 | ): Promise<void> { |
| 23 | const target = await promptForPlatformTarget( |
| 24 | await getPlatformTargets('android'), |
| 25 | selectedTarget ?? selectedTargetName, |
| 26 | selectedTargetSdkVersion, |
| 27 | selectedTargetName !== undefined, |
| 28 | ); |
| 29 | |
| 30 | const runFlavor = selectedFlavor || config.android?.flavor || ''; |
| 31 | |
| 32 | const arg = `assemble${runFlavor}Debug`; |
| 33 | const gradleArgs = [arg]; |
| 34 | |
| 35 | debug('Invoking ./gradlew with args: %O', gradleArgs); |
| 36 | |
| 37 | try { |
| 38 | await runTask('Running Gradle build', async () => |
| 39 | runCommand('./gradlew', gradleArgs, { |
| 40 | cwd: config.android.platformDirAbs, |
| 41 | }), |
| 42 | ); |
| 43 | } catch (e: any) { |
| 44 | if (e.includes('EACCES')) { |
| 45 | 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( |
| 46 | `chmod +x ./${config.android.platformDir}/gradlew`, |
| 47 | )} and try again.`; |
| 48 | } else { |
| 49 | throw e; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | const pathToApk = `${config.android.platformDirAbs}/${ |
| 54 | config.android.appDir |
| 55 | }/build/outputs/apk${runFlavor !== '' ? '/' + runFlavor : ''}/debug`; |
| 56 | |
| 57 | const apkName = parseApkNameFromFlavor(runFlavor); |
| 58 | const apkPath = resolve(pathToApk, apkName); |
| 59 | |
| 60 | const nativeRunArgs = ['android', '--app', apkPath, '--target', target.id]; |
| 61 | |
| 62 | if (selectedPorts) { |
| 63 | nativeRunArgs.push('--forward', `${selectedPorts}`); |
| 64 | } |
| 65 | |
| 66 | debug('Invoking native-run with args: %O', nativeRunArgs); |
| 67 | |
| 68 | await runTask(`Deploying ${c.strong(apkName)} to ${c.input(target.id)}`, async () => runNativeRun(nativeRunArgs)); |
| 69 | } |
no test coverage detected