Skip to content
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
1 change: 1 addition & 0 deletions docs/man_pages/project/testing/build-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ General | `$ ns build android [--compileSdk <API Level>] [--key-store-path <File
* `--env.sourceMap` - creates inline source maps.
* `--env.hiddenSourceMap` - creates sources maps in the root folder (useful for Crashlytics usage with bundled app in release).
* `--aab` - Specifies that the build will produce an Android App Bundle(`.aab`) file.
* `--gradleFlavor` - Builds the given product flavor, when the app declares any. `--gradleFlavor foo` runs the `assembleFooDebug`/`assembleFooRelease` gradle task instead of `assembleDebug`/`assembleRelease`.
* `--force` - If set, skips the application compatibility checks and forces `npm i` to ensure all dependencies are installed. Otherwise, the command will check the application compatibility with the current CLI version and could fail requiring `ns migrate`.
* `--path <Directory>` - Specifies the directory that contains the project. If not set, the project is searched for in the current directory and all directories above it.

Expand Down
1 change: 1 addition & 0 deletions docs/man_pages/project/testing/debug-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Attach the debug tools to a running app in the native emulator | `$ ns debug and
* `--env.sourceMap` - creates inline source maps.
* `--env.hiddenSourceMap` - creates sources maps in the root folder (useful for Crashlytics usage with bundled app in release).
* `--aab` - Specifies that the command will produce and deploy an Android App Bundle.
* `--gradleFlavor` - Builds the given product flavor, when the app declares any. `--gradleFlavor foo` runs the `assembleFooDebug`/`assembleFooRelease` gradle task instead of `assembleDebug`/`assembleRelease`.
* `--force` - If set, skips the application compatibility checks and forces `npm i` to ensure all dependencies are installed. Otherwise, the command will check the application compatibility with the current CLI version and could fail requiring `ns migrate`.

<% if(isHtml) { %>
Expand Down
1 change: 1 addition & 0 deletions docs/man_pages/project/testing/run-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Start a default emulator if none are running, or run application on all connecte
* `--env.sourceMap` - creates inline source maps.
* `--env.hiddenSourceMap` - creates sources maps in the root folder (useful for Crashlytics usage with bundled app in release).
* `--aab` - Specifies that the command will produce and deploy an Android App Bundle.
* `--gradleFlavor` - Builds the given product flavor, when the app declares any. `--gradleFlavor foo` runs the `assembleFooDebug`/`assembleFooRelease` gradle task instead of `assembleDebug`/`assembleRelease`.
* `--force` - If set, skips the application compatibility checks and forces `npm i` to ensure all dependencies are installed. Otherwise, the command will check the application compatibility with the current CLI version and could fail requiring `ns migrate`.

<% if(isHtml) { %>
Expand Down
2 changes: 2 additions & 0 deletions lib/data/build-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class AndroidBuildData extends BuildData {
public keyStoreAliasPassword: string;
public keyStorePassword: string;
public androidBundle: boolean;
public gradleFlavor: string;
public gradlePath: string;
public gradleArgs: string;
public hostProjectPath: string;
Expand All @@ -63,6 +64,7 @@ export class AndroidBuildData extends BuildData {
this.keyStoreAliasPassword = data.keyStoreAliasPassword;
this.keyStorePassword = data.keyStorePassword;
this.androidBundle = data.androidBundle || data.aab;
this.gradleFlavor = data.gradleFlavor;
this.gradlePath = data.gradlePath;
this.gradleArgs = data.gradleArgs;
this.hostProjectPath = data.hostProjectPath;
Expand Down
5 changes: 5 additions & 0 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ interface IEmbedOptions {
}

interface IAndroidOptions extends IEmbedOptions {
/**
* The product flavor to build, when the app declares any. `--gradleFlavor foo`
* runs `assembleFooDebug` instead of `assembleDebug`.
*/
gradleFlavor: string;
gradlePath: string;
gradleArgs: string;
}
Expand Down
1 change: 1 addition & 0 deletions lib/definitions/build.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface IAndroidBuildData
extends IBuildData,
IAndroidSigningData,
IHasAndroidBundle {
gradleFlavor?: string;
gradlePath?: string;
gradleArgs?: string;
}
Expand Down
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class Options {
default: false,
hasSensitiveValue: false,
},
gradleFlavor: { type: OptionType.String, hasSensitiveValue: false },
gradlePath: { type: OptionType.String, hasSensitiveValue: false },
gradleArgs: { type: OptionType.String, hasSensitiveValue: false },
hostProjectPath: { type: OptionType.String, hasSensitiveValue: false },
Expand Down
10 changes: 9 additions & 1 deletion lib/services/android/gradle-build-args-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ export class GradleBuildArgsService implements IGradleBuildArgsService {
}

private getBuildTaskName(buildData: IAndroidBuildData): string {
const baseTaskName = buildData.androidBundle ? "bundle" : "assemble";
let baseTaskName = buildData.androidBundle ? "bundle" : "assemble";

// a product flavor sits between the task and the build type -
// `assembleFooRelease`, `bundleFooDebug`
const flavor = buildData.gradleFlavor;
if (flavor) {
baseTaskName += flavor[0].toUpperCase() + flavor.slice(1);
}

const buildTaskName = buildData.release
? `${baseTaskName}${Configurations.Release}`
: `${baseTaskName}${Configurations.Debug}`;
Expand Down
50 changes: 50 additions & 0 deletions test/services/android/gradle-build-args-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,56 @@ describe("GradleBuildArgsService", () => {
);
});

describe("gradleFlavor", async () => {
const testCases = [
{
name: "should build the flavor of a debug build",
buildConfig: { release: false, gradleFlavor: "foo" },
logLevel: "INFO",
expectedTask: "assembleFooDebug",
},
{
name: "should build the flavor of a release build",
buildConfig: { ...releaseBuildConfig, gradleFlavor: "foo" },
logLevel: "INFO",
expectedTask: "assembleFooRelease",
},
{
name: "should build the flavor of an android bundle",
buildConfig: {
release: false,
androidBundle: true,
gradleFlavor: "foo",
},
logLevel: "INFO",
expectedTask: "bundleFooDebug",
},
{
name: "should keep an already capitalized flavor",
buildConfig: { release: false, gradleFlavor: "Foo" },
logLevel: "INFO",
expectedTask: "assembleFooDebug",
},
];

for (const testCase of testCases) {
it(testCase.name, async () => {
const injector = createTestInjector();
const logger = injector.resolve("logger");
logger.getLevel = () => testCase.logLevel;

const gradleBuildArgsService = injector.resolve(
"gradleBuildArgsService"
);
const args = await gradleBuildArgsService.getBuildTaskArgs(
<any>testCase.buildConfig
);

assert.deepStrictEqual(args[0], testCase.expectedTask);
});
}
});

describe("getCleanTaskArgs", async () => {
const testCases = [
{
Expand Down