Skip to content

Commit e85406e

Browse files
authored
Merge pull request #5079 from NativeScript/tachev/run-with-aab
fix: add more signing validations
2 parents bd1e839 + 8669744 commit e85406e

File tree

8 files changed

+75
-15
lines changed

8 files changed

+75
-15
lines changed

lib/commands/build.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages } from "../constants";
1+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
22
import { ValidatePlatformCommandBase } from "./command-base";
3+
import { hasValidAndroidSigning } from "../common/helpers";
34

45
export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
56
constructor($options: IOptions,
@@ -123,8 +124,12 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
123124
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
124125
let canExecute = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
125126
if (canExecute) {
126-
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
127-
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
127+
if ((this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
128+
if (this.$options.release) {
129+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
130+
} else {
131+
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
132+
}
128133
}
129134

130135
canExecute = await super.validateArgs(args, platform);

lib/commands/debug.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { cache } from "../common/decorators";
22
import { ValidatePlatformCommandBase } from "./command-base";
3+
import { hasValidAndroidSigning } from "../common/helpers";
4+
import { ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
35

46
export class DebugPlatformCommand extends ValidatePlatformCommandBase implements ICommand {
57
public allowedParameters: ICommandParameter[] = [];
@@ -155,7 +157,8 @@ export class DebugAndroidCommand implements ICommand {
155157
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
156158
private $injector: IInjector,
157159
private $projectData: IProjectData,
158-
private $markingModeService: IMarkingModeService) {
160+
private $markingModeService: IMarkingModeService,
161+
private $options: IOptions) {
159162
this.$projectData.initializeProjectData();
160163
}
161164

@@ -164,8 +167,14 @@ export class DebugAndroidCommand implements ICommand {
164167
return this.debugPlatformCommand.execute(args);
165168
}
166169
public async canExecute(args: string[]): Promise<boolean> {
167-
const result = await this.debugPlatformCommand.canExecute(args);
168-
return result;
170+
const canExecuteBase = await this.debugPlatformCommand.canExecute(args);
171+
if (canExecuteBase) {
172+
if (this.$options.aab && !hasValidAndroidSigning(this.$options)) {
173+
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
174+
}
175+
}
176+
177+
return canExecuteBase;
169178
}
170179

171180
public platform = this.$devicePlatformsConstants.Android;

lib/commands/deploy.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
1+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
22
import { ValidatePlatformCommandBase } from "./command-base";
33
import { DeployCommandHelper } from "../helpers/deploy-command-helper";
4+
import { hasValidAndroidSigning } from "../common/helpers";
45

56
export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implements ICommand {
67
public allowedParameters: ICommandParameter[] = [];
@@ -47,8 +48,12 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
4748
return false;
4849
}
4950

50-
if (this.$mobileHelper.isAndroidPlatform(platform) && this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
51-
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
51+
if (this.$mobileHelper.isAndroidPlatform(platform) && (this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
52+
if (this.$options.release) {
53+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
54+
} else {
55+
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
56+
}
5257
}
5358

5459
const result = await super.canExecuteCommandBase(platform, { validateOptions: true });

lib/commands/run.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
2-
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
33
import { cache } from "../common/decorators";
4+
import { hasValidAndroidSigning } from "../common/helpers";
45

56
export class RunCommandBase implements ICommand {
67
private liveSyncCommandHelperAdditionalOptions: ILiveSyncCommandHelperAdditionalOptions = <ILiveSyncCommandHelperAdditionalOptions>{};
@@ -126,8 +127,12 @@ export class RunAndroidCommand implements ICommand {
126127
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.Android} can not be built on this OS`);
127128
}
128129

129-
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
130-
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
130+
if ((this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
131+
if (this.$options.release) {
132+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
133+
} else {
134+
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
135+
}
131136
}
132137

133138
return this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$devicePlatformsConstants.Android.toLowerCase());

lib/commands/test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { hasValidAndroidSigning } from "../common/helpers";
2+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE } from "../constants";
3+
14
abstract class TestCommandBase {
25
public allowedParameters: ICommandParameter[] = [];
36
public dashedOptions = {
@@ -111,6 +114,21 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
111114
await this.$markingModeService.handleMarkingModeFullDeprecation({ projectDir: this.$projectData.projectDir, skipWarnings: true });
112115
await super.execute(args);
113116
}
117+
118+
async canExecute(args: string[]): Promise<boolean> {
119+
const canExecuteBase = await super.canExecute(args);
120+
if (canExecuteBase) {
121+
if ((this.$options.release || this.$options.aab) && !hasValidAndroidSigning(this.$options)) {
122+
if (this.$options.release) {
123+
this.$errors.failWithHelp(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
124+
} else {
125+
this.$errors.failWithHelp(ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE);
126+
}
127+
}
128+
}
129+
130+
return canExecuteBase;
131+
}
114132
}
115133

116134
class TestIosCommand extends TestCommandBase implements ICommand {

lib/common/helpers.ts

+15
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,19 @@ export function annotate(fn: any) {
736736
return $inject;
737737
}
738738

739+
/**
740+
* Returns true if all Android signing options are provided, false otherwise.
741+
* @param {IAndroidSigningData} signingData The signing data to be validated.
742+
* @return {void}
743+
*/
744+
export function hasValidAndroidSigning(signingData: Partial<IAndroidSigningData>): boolean {
745+
const isValid = signingData &&
746+
signingData.keyStorePath &&
747+
signingData.keyStorePassword &&
748+
signingData.keyStoreAlias &&
749+
signingData.keyStoreAliasPassword;
750+
751+
return !!isValid;
752+
}
753+
739754
//--- end part copied from AngularJS

lib/constants.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export const DEBUGGER_DETACHED_EVENT_NAME = "debuggerDetached";
150150
export const VERSION_STRING = "version";
151151
export const INSPECTOR_CACHE_DIRNAME = "ios-inspector";
152152
export const POST_INSTALL_COMMAND_NAME = "post-install-cli";
153-
export const ANDROID_RELEASE_BUILD_ERROR_MESSAGE = "When producing a release build, you need to specify all --key-store-* options.";
153+
const ANDROID_SIGNING_REQUIRED_MESSAGE = "you need to specify all --key-store-* options.";
154+
export const ANDROID_RELEASE_BUILD_ERROR_MESSAGE = `When producing a release build, ${ANDROID_SIGNING_REQUIRED_MESSAGE}`;
155+
export const ANDROID_APP_BUNDLE_SIGNING_ERROR_MESSAGE = `When producing Android App Bundle, ${ANDROID_SIGNING_REQUIRED_MESSAGE}`;
154156
export const CACACHE_DIRECTORY_NAME = "_cacache";
155157

156158
export const FILES_CHANGE_EVENT_NAME = "filesChangeEvent";

lib/services/android/android-bundle-tool-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolve, join } from "path";
2+
import { hasValidAndroidSigning } from "../../common/helpers";
23

34
export class AndroidBundleToolService implements IAndroidBundleToolService {
45
private javaPath: string;
@@ -12,8 +13,8 @@ export class AndroidBundleToolService implements IAndroidBundleToolService {
1213
}
1314

1415
public async buildApks(options: IBuildApksOptions): Promise<void> {
15-
if (!options.signingData) {
16-
this.$errors.fail(`Unable to build "apks" without a signing information.`);
16+
if (!hasValidAndroidSigning(options.signingData)) {
17+
this.$errors.fail(`Unable to build "apks" without a full signing information.`);
1718
}
1819

1920
const aabToolResult = await this.execBundleTool([

0 commit comments

Comments
 (0)