From d7b23f21c554c94029b24d6e0c9ad4635f055759 Mon Sep 17 00:00:00 2001 From: Julien Ferand Date: Thu, 14 Mar 2024 12:51:54 +0100 Subject: [PATCH] fix(cli): apkName for multi-dimensional flavors (#6704) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mark Anderson Co-authored-by: Dan Giralté <97970732+giralte-ionic@users.noreply.github.com> --- cli/src/android/run.ts | 9 ++++++--- cli/src/common.ts | 5 +++++ cli/src/config.ts | 5 ++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cli/src/android/run.ts b/cli/src/android/run.ts index 824994e61..226a4259c 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 { + parseApkNameFromFlavor, + promptForPlatformTarget, + runTask, +} from '../common'; import type { Config } from '../definitions'; import type { RunCommandOptions } from '../tasks/run'; import { runNativeRun, getPlatformTargets } from '../util/native-run'; @@ -50,8 +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); const nativeRunArgs = ['android', '--app', apkPath, '--target', target.id]; 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 127284f88..d4207ed97 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, @@ -249,13 +250,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));