diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 8662aa97f9..0000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/docs/man_pages/project/testing/build-android.md b/docs/man_pages/project/testing/build-android.md index 24c9ec8642..2c0cfe2158 100644 --- a/docs/man_pages/project/testing/build-android.md +++ b/docs/man_pages/project/testing/build-android.md @@ -3,7 +3,7 @@ build android Usage | Synopsis ---|--- -General | `$ tns build android [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release]` +General | `$ tns build android [--key-store-path --key-store-password --key-store-alias --key-store-alias-password ] [--release] [--static-bindings]` Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator. @@ -13,6 +13,7 @@ Builds the project for Android and produces an APK that you can manually deploy * `--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. * `--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. * `--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. +* `--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. <% if(isHtml) { %> ### Related Commands diff --git a/lib/commands/build.ts b/lib/commands/build.ts index 23adc6904d..4a2736f6e8 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -4,8 +4,8 @@ export class BuildCommandBase { constructor(private $platformService: IPlatformService) { } - executeCore(args: string[]): IFuture { - return this.$platformService.buildPlatform(args[0]); + executeCore(args: string[], buildConfig?: IBuildConfig): IFuture { + return this.$platformService.buildPlatform(args[0], buildConfig); } } @@ -25,14 +25,16 @@ $injector.registerCommand("build|ios", BuildIosCommand); export class BuildAndroidCommand extends BuildCommandBase implements ICommand { constructor($platformService: IPlatformService, - private $platformsData: IPlatformsData) { + private $platformsData: IPlatformsData, + private $options: IOptions) { super($platformService); } - public allowedParameters: ICommandParameter[] = []; - public execute(args: string[]): IFuture { - return this.executeCore([this.$platformsData.availablePlatforms.Android]); + let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined; + return this.executeCore([this.$platformsData.availablePlatforms.Android], config); } + + public allowedParameters: ICommandParameter[] = []; } $injector.registerCommand("build|android", BuildAndroidCommand); diff --git a/lib/declarations.ts b/lib/declarations.ts index b5ba12ac0e..4bbe0e267f 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -80,6 +80,7 @@ interface IOptions extends ICommonOptions { sdk: string; ignoreScripts: boolean; tnsModulesVersion: string; + staticBindings: boolean; } interface IProjectFilesManager { diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index 120719878b..bc2cb17b5c 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -7,7 +7,7 @@ interface IPlatformService { updatePlatforms(platforms: string[]): IFuture; runPlatform(platform: string): IFuture; preparePlatform(platform: string): IFuture; - buildPlatform(platform: string): IFuture; + buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture; deployOnDevice(platform: string): IFuture; deployOnEmulator(platform: string): IFuture; validatePlatformInstalled(platform: string): void; diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 81bf139182..b1360da096 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -26,13 +26,17 @@ interface IPlatformProjectServiceBase { getPluginPlatformsFolderPath(pluginData: IPluginData, platform: string): string; } +interface IBuildConfig { + runSbGenerator?: boolean; +} + interface IPlatformProjectService { platformData: IPlatformData; validate(): IFuture; createProject(projectRoot: string, frameworkDir: string): IFuture; interpolateData(projectRoot: string): IFuture; afterCreateProject(projectRoot: string): IFuture; - buildProject(projectRoot: string): IFuture; + buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture; prepareProject(): IFuture; prepareAppResources(appResourcesDirectoryPath: string): IFuture; isPlatformPrepared(projectRoot: string): IFuture; diff --git a/lib/options.ts b/lib/options.ts index 1e56d7d130..6a6fd53138 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -28,7 +28,8 @@ export class Options extends commonOptionsLibPath.OptionsBase { keyStoreAliasPassword: { type: OptionType.String }, sdk: { type: OptionType.String }, ignoreScripts: {type: OptionType.Boolean }, - tnsModulesVersion: { type: OptionType.String } + tnsModulesVersion: { type: OptionType.String }, + staticBindings: {type: OptionType.Boolean} }, path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"), $errors, $staticConfig); diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 28c19cf03b..9e171caa46 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -175,7 +175,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService return Future.fromResult(); } - public buildProject(projectRoot: string): IFuture { + public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture { return (() => { if(this.canUseGradle().wait()) { let buildOptions = ["buildapk", `-PcompileSdk=${this.getAndroidTarget().wait()}`]; @@ -187,6 +187,10 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`); } + if (buildConfig && buildConfig.runSbGenerator) { + buildOptions.push("-PrunSBGenerator"); + } + this.spawn("gradle", buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait(); } else { this.checkAnt().wait(); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 8e3bd313ee..1623fb2630 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -193,13 +193,13 @@ export class PlatformService implements IPlatformService { }).future()(); } - public buildPlatform(platform: string): IFuture { + public buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture { return (() => { platform = platform.toLowerCase(); this.preparePlatform(platform).wait(); let platformData = this.$platformsData.getPlatformData(platform); - platformData.platformProjectService.buildProject(platformData.projectRoot).wait(); + platformData.platformProjectService.buildProject(platformData.projectRoot, buildConfig).wait(); this.$logger.out("Project successfully built"); }).future()(); }