Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): allow run command to use flavors #4782

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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