diff --git a/lib/commands/build.ts b/lib/commands/build.ts index 9d944593c9..5d52966ea0 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -40,8 +40,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand { } public execute(args: string[]): IFuture { - let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined; - return this.executeCore([this.$platformsData.availablePlatforms.Android], config); + return this.executeCore([this.$platformsData.availablePlatforms.Android]); } public allowedParameters: ICommandParameter[] = []; diff --git a/lib/commands/deploy.ts b/lib/commands/deploy.ts index 1e23fad314..a6ba8953f2 100644 --- a/lib/commands/deploy.ts +++ b/lib/commands/deploy.ts @@ -9,8 +9,7 @@ export class DeployOnDeviceCommand implements ICommand { private $mobileHelper: Mobile.IMobileHelper) { } execute(args: string[]): IFuture { - let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined; - return this.$platformService.deployOnDevice(args[0], config); + return this.$platformService.deployOnDevice(args[0]); } public canExecute(args: string[]): IFuture { diff --git a/lib/commands/run.ts b/lib/commands/run.ts index 757a5f3c4b..bd6f08ac6f 100644 --- a/lib/commands/run.ts +++ b/lib/commands/run.ts @@ -34,8 +34,7 @@ export class RunAndroidCommand extends RunCommandBase implements ICommand { public allowedParameters: ICommandParameter[] = []; public execute(args: string[]): IFuture { - let config = this.$options.staticBindings ? { runSbGenerator: true } : undefined; - return this.executeCore([this.$platformsData.availablePlatforms.Android], config); + return this.executeCore([this.$platformsData.availablePlatforms.Android]); } public canExecute(args: string[]): IFuture { diff --git a/lib/common b/lib/common index b59b402046..a2e731bafc 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit b59b40204622e7738c5044bad4aaee11008dffa3 +Subproject commit a2e731bafcc2304e20540180eb49b7ccb4ff556f diff --git a/lib/declarations.ts b/lib/declarations.ts index 14aa5848f1..b89c45345b 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -85,7 +85,6 @@ interface IOptions extends ICommonOptions { port: Number; production: boolean; sdk: string; - staticBindings: boolean; symlink: boolean; tnsModulesVersion: string; } diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 563a47cb65..215fc7e108 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -47,7 +47,6 @@ interface IPlatformProjectServiceBase { } interface IBuildConfig { - runSbGenerator?: boolean; buildForDevice?: boolean; architectures?: string[]; } diff --git a/lib/options.ts b/lib/options.ts index 4a314c9645..babc41afdd 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -30,7 +30,6 @@ export class Options extends commonOptionsLibPath.OptionsBase { keyStoreAliasPassword: { type: OptionType.String }, ignoreScripts: {type: OptionType.Boolean }, tnsModulesVersion: { type: OptionType.String }, - staticBindings: {type: OptionType.Boolean}, compileSdk: {type: OptionType.Number }, port: { type: OptionType.Number }, copyTo: { type: OptionType.String }, diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index dfad2c056c..eb09ee0e24 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -16,6 +16,18 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v"; private static ANDROID_PLATFORM_NAME = "android"; private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.3.0"; + private static MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS = "4.2.1"; + private static REQUIRED_DEV_DEPENDENCIES = [ + { name: "babel-traverse", version: "^6.4.5"}, + { name: "babel-types", version: "^6.4.5"}, + { name: "babylon", version: "^6.4.5"}, + { name: "filewalker", version: "^0.1.2"}, + { name: "lazy", version: "^1.0.11"} + ]; + + private get sysInfoData(): ISysInfoData { + return this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait(); + } private _androidProjectPropertiesManagers: IDictionary; @@ -36,7 +48,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject private $deviceAppDataFactory: Mobile.IDeviceAppDataFactory, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $projectTemplatesService: IProjectTemplatesService, - private $xmlValidator: IXmlValidator) { + private $xmlValidator: IXmlValidator, + private $npm: INodePackageManager) { super($fs, $projectData, $projectDataService); this._androidProjectPropertiesManagers = Object.create(null); } @@ -88,7 +101,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject // this call will fail in case `android` is not set correctly. this.$androidToolsInfo.getPathToAndroidExecutable({showWarningsAsErrors: true}).wait(); - this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait(); + this.$androidToolsInfo.validateJavacVersion(this.sysInfoData.javacVersion, {showWarningsAsErrors: true}).wait(); }).future()(); } @@ -126,10 +139,28 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject } this.cleanResValues(targetSdkVersion, frameworkVersion).wait(); - + if(this.canUseStaticBindingGenerator()) { + let npmConfig = { + "save": true, + "save-dev": true, + "save-exact": true, + "silent": true + }; + + _.each(AndroidProjectService.REQUIRED_DEV_DEPENDENCIES, (dependency: any) => + this.$npm.install(`${dependency.name}@${dependency.version}`, this.$projectData.projectDir, npmConfig).wait() + ); + } else { + this.$logger.printMarkdown(` As you are using Node.js \`${this.sysInfoData.nodeVer}\` Static Binding Generator will be turned off.` + + `Upgrade your Node.js to ${AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS} or later, so you can use this feature.`); + } }).future()(); } + private canUseStaticBindingGenerator(): boolean { + return semver.gte(this.sysInfoData.nodeVer, AndroidProjectService.MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS); + } + private useGradleWrapper(frameworkDir: string): boolean { let gradlew = path.join(frameworkDir, "gradlew"); return this.$fs.exists(gradlew).wait(); @@ -231,8 +262,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject buildOptions.push(`-PksPassword=${this.$options.keyStorePassword}`); } - if (buildConfig && buildConfig.runSbGenerator) { - buildOptions.push("-PrunSBGenerator"); + if(!this.canUseStaticBindingGenerator()) { + buildOptions.push("-PdontRunSbg"); } let gradleBin = this.useGradleWrapper(projectRoot) ? path.join(projectRoot, "gradlew") : "gradle"; diff --git a/lib/services/project-data-service.ts b/lib/services/project-data-service.ts index ff2f17aa98..d19732d729 100644 --- a/lib/services/project-data-service.ts +++ b/lib/services/project-data-service.ts @@ -60,13 +60,11 @@ export class ProjectDataService implements IProjectDataService { return (() => { assert.ok(this.projectFilePath, "Initialize method of projectDataService is not called."); - if(!this.projectData) { - if(!this.$fs.exists(this.projectFilePath).wait()) { - this.$fs.writeFile(this.projectFilePath, null).wait(); - } - - this.projectData = this.$fs.readJson(this.projectFilePath).wait() || Object.create(null); + if(!this.$fs.exists(this.projectFilePath).wait()) { + this.$fs.writeFile(this.projectFilePath, null).wait(); } + + this.projectData = this.$fs.readJson(this.projectFilePath).wait() || Object.create(null); }).future()(); } }