diff --git a/cli/src/android/run.ts b/cli/src/android/run.ts index 824994e61..700a1e451 100644 --- a/cli/src/android/run.ts +++ b/cli/src/android/run.ts @@ -2,7 +2,11 @@ import Debug from 'debug'; import { resolve } from 'path'; import c from '../colors'; -import { promptForPlatformTarget, runTask } from '../common'; +import { + promptForPlatformTarget, + parseApkNameFromFlavor, + runTask, +} from '../common'; import type { Config } from '../definitions'; import type { RunCommandOptions } from '../tasks/run'; import { runNativeRun, getPlatformTargets } from '../util/native-run'; @@ -50,7 +54,7 @@ export async function runAndroid( config.android.appDir }/build/outputs/apk${runFlavor !== '' ? '/' + runFlavor : ''}/debug`; - const apkName = `app${runFlavor !== '' ? '-' + runFlavor : ''}-debug.apk`; + const apkName = parseApkNameFromFlavor(runFlavor); const apkPath = resolve(pathToApk, apkName); diff --git a/cli/src/common.ts b/cli/src/common.ts index 2d184c843..20d9d6214 100644 --- a/cli/src/common.ts +++ b/cli/src/common.ts @@ -573,3 +573,8 @@ export async function checkJDKMajorVersion(): Promise { return -1; } } + +export function parseApkNameFromFlavor(flavor: string): string { + const convertedName = flavor.replace(/([A-Z])/g, '-$1').toLowerCase(); + return `app-${convertedName ? `${convertedName}-` : ''}debug.apk`; +} diff --git a/cli/src/config.ts b/cli/src/config.ts index f617ce32d..a3e253c26 100644 --- a/cli/src/config.ts +++ b/cli/src/config.ts @@ -9,6 +9,7 @@ import Debug from 'debug'; import { dirname, extname, join, relative, resolve } from 'path'; import c from './colors'; +import { parseApkNameFromFlavor } from './common'; import type { AndroidConfig, AppConfig, @@ -247,13 +248,11 @@ async function loadAndroidConfig( const webDir = `${assetsDir}/public`; const resDir = `${srcMainDir}/res`; let apkPath = `${appDir}/build/outputs/apk/`; - let flavorPrefix = ''; const flavor = extConfig.android?.flavor || ''; if (extConfig.android?.flavor) { apkPath = `${apkPath}/${extConfig.android?.flavor}`; - flavorPrefix = `-${extConfig.android?.flavor}`; } - const apkName = `app${flavorPrefix}-debug.apk`; + const apkName = parseApkNameFromFlavor(flavor); const buildOutputDir = `${apkPath}/debug`; const cordovaPluginsDir = 'capacitor-cordova-android-plugins'; const studioPath = lazy(() => determineAndroidStudioPath(cliConfig.os));