Skip to content

Commit

Permalink
fix(cli): apkName for multi-dimensional flavors (#6704)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Anderson <[email protected]>
Co-authored-by: Dan Giralté <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent 9eb565c commit d7b23f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cli/src/android/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions cli/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,8 @@ export async function checkJDKMajorVersion(): Promise<number> {
return -1;
}
}

export function parseApkNameFromFlavor(flavor: string): string {
const convertedName = flavor.replace(/([A-Z])/g, '-$1').toLowerCase();
return `app-${convertedName ? `${convertedName}-` : ''}debug.apk`;
}
5 changes: 2 additions & 3 deletions cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit d7b23f2

Please sign in to comment.