Skip to content

Commit 065e3b1

Browse files
committed
Merge pull request #843 from NativeScript/totev/gradle-runsbgenerator
Implement command line option to run static bindings generator
2 parents 2b6f0b0 + c24a1a5 commit 065e3b1

File tree

9 files changed

+26
-17
lines changed

9 files changed

+26
-17
lines changed

.idea/misc.xml

-4
This file was deleted.

docs/man_pages/project/testing/build-android.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build android
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release]`
6+
General | `$ tns build android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings]`
77

88
Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator.
99

@@ -13,6 +13,7 @@ Builds the project for Android and produces an APK that you can manually deploy
1313
* `--key-store-password` - Provides the password for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1414
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1515
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
16+
* `--static-bindings` - If set, generates static bindings from your JavaScript code to corresponding native Android APIs during build. This static bindings speed up app loading.
1617

1718
<% if(isHtml) { %>
1819
### Related Commands

lib/commands/build.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
export class BuildCommandBase {
55
constructor(private $platformService: IPlatformService) { }
66

7-
executeCore(args: string[]): IFuture<void> {
8-
return this.$platformService.buildPlatform(args[0]);
7+
executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
8+
return this.$platformService.buildPlatform(args[0], buildConfig);
99
}
1010
}
1111

@@ -25,14 +25,16 @@ $injector.registerCommand("build|ios", BuildIosCommand);
2525

2626
export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
2727
constructor($platformService: IPlatformService,
28-
private $platformsData: IPlatformsData) {
28+
private $platformsData: IPlatformsData,
29+
private $options: IOptions) {
2930
super($platformService);
3031
}
3132

32-
public allowedParameters: ICommandParameter[] = [];
33-
3433
public execute(args: string[]): IFuture<void> {
35-
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
34+
let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined;
35+
return this.executeCore([this.$platformsData.availablePlatforms.Android], config);
3636
}
37+
38+
public allowedParameters: ICommandParameter[] = [];
3739
}
3840
$injector.registerCommand("build|android", BuildAndroidCommand);

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ interface IOptions extends ICommonOptions {
8080
sdk: string;
8181
ignoreScripts: boolean;
8282
tnsModulesVersion: string;
83+
staticBindings: boolean;
8384
}
8485

8586
interface IProjectFilesManager {

lib/definitions/platform.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface IPlatformService {
77
updatePlatforms(platforms: string[]): IFuture<void>;
88
runPlatform(platform: string): IFuture<void>;
99
preparePlatform(platform: string): IFuture<void>;
10-
buildPlatform(platform: string): IFuture<void>;
10+
buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
1111
deployOnDevice(platform: string): IFuture<void>;
1212
deployOnEmulator(platform: string): IFuture<void>;
1313
validatePlatformInstalled(platform: string): void;

lib/definitions/project.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ interface IPlatformProjectServiceBase {
2626
getPluginPlatformsFolderPath(pluginData: IPluginData, platform: string): string;
2727
}
2828

29+
interface IBuildConfig {
30+
runSbGenerator?: boolean;
31+
}
32+
2933
interface IPlatformProjectService {
3034
platformData: IPlatformData;
3135
validate(): IFuture<void>;
3236
createProject(projectRoot: string, frameworkDir: string): IFuture<void>;
3337
interpolateData(projectRoot: string): IFuture<void>;
3438
afterCreateProject(projectRoot: string): IFuture<void>;
35-
buildProject(projectRoot: string): IFuture<void>;
39+
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
3640
prepareProject(): IFuture<void>;
3741
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
3842
isPlatformPrepared(projectRoot: string): IFuture<boolean>;

lib/options.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
2828
keyStoreAliasPassword: { type: OptionType.String },
2929
sdk: { type: OptionType.String },
3030
ignoreScripts: {type: OptionType.Boolean },
31-
tnsModulesVersion: { type: OptionType.String }
31+
tnsModulesVersion: { type: OptionType.String },
32+
staticBindings: {type: OptionType.Boolean}
3233
},
3334
path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
3435
$errors, $staticConfig);

lib/services/android-project-service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
175175
return Future.fromResult();
176176
}
177177

178-
public buildProject(projectRoot: string): IFuture<void> {
178+
public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
179179
return (() => {
180180
if(this.canUseGradle().wait()) {
181181
let buildOptions = ["buildapk", `-PcompileSdk=${this.getAndroidTarget().wait()}`];
@@ -187,6 +187,10 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
187187
buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`);
188188
}
189189

190+
if (buildConfig && buildConfig.runSbGenerator) {
191+
buildOptions.push("-PrunSBGenerator");
192+
}
193+
190194
this.spawn("gradle", buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
191195
} else {
192196
this.checkAnt().wait();

lib/services/platform-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ export class PlatformService implements IPlatformService {
193193
}).future<void>()();
194194
}
195195

196-
public buildPlatform(platform: string): IFuture<void> {
196+
public buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
197197
return (() => {
198198
platform = platform.toLowerCase();
199199
this.preparePlatform(platform).wait();
200200

201201
let platformData = this.$platformsData.getPlatformData(platform);
202-
platformData.platformProjectService.buildProject(platformData.projectRoot).wait();
202+
platformData.platformProjectService.buildProject(platformData.projectRoot, buildConfig).wait();
203203
this.$logger.out("Project successfully built");
204204
}).future<void>()();
205205
}

0 commit comments

Comments
 (0)