Skip to content

Commit

Permalink
feat(cli): allow run command to use flavors (#4782)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jul 7, 2021
1 parent 2b7016f commit 05cb853
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
9 changes: 5 additions & 4 deletions cli/src/android/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ export async function runAndroid(
cwd: config.android.platformDirAbs,
}),
);

const apkName = 'app-debug.apk';
const apkPath = resolve(config.android.buildOutputDirAbs, apkName);
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(apkName)} to ${c.input(target.id)}`,
`Deploying ${c.strong(config.android.apkName)} to ${c.input(target.id)}`,
async () => runNativeRun(nativeRunArgs),
);
}
10 changes: 9 additions & 1 deletion cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ async function loadAndroidConfig(
const assetsDir = `${srcMainDir}/assets`;
const webDir = `${assetsDir}/public`;
const resDir = `${srcMainDir}/res`;
const buildOutputDir = `${appDir}/build/outputs/apk/debug`;
let apkPath = `${appDir}/build/outputs/apk/`;
let flavorPrefix = '';
if (extConfig.android?.flavor) {
apkPath = `${apkPath}/${extConfig.android?.flavor}`;
flavorPrefix = `-${extConfig.android?.flavor}`;
}
const apkName = `app${flavorPrefix}-debug.apk`;
const buildOutputDir = `${apkPath}/debug`;
const cordovaPluginsDir = 'capacitor-cordova-android-plugins';
const studioPath = lazy(() => determineAndroidStudioPath(cliConfig.os));

Expand All @@ -251,6 +258,7 @@ async function loadAndroidConfig(
webDirAbs: resolve(platformDirAbs, webDir),
resDir,
resDirAbs: resolve(platformDirAbs, resDir),
apkName,
buildOutputDir,
buildOutputDirAbs: resolve(platformDirAbs, buildOutputDir),
};
Expand Down
10 changes: 10 additions & 0 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ export interface CapacitorConfig {
* @since 3.0.0
*/
includePlugins?: string[];

/**
* Android flavor to use.
*
* If the app has flavors declared in the `build.gradle`
* configure the flavor you want to run with `npx cap run` command.
*
* @since 3.1.0
*/
flavor?: string;
};

ios?: {
Expand Down
1 change: 1 addition & 0 deletions cli/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface AndroidConfig extends PlatformConfig {
readonly resDirAbs: string;
readonly buildOutputDir: string;
readonly buildOutputDirAbs: string;
readonly apkName: string;
}

export interface IOSConfig extends PlatformConfig {
Expand Down

0 comments on commit 05cb853

Please sign in to comment.