@@ -16,6 +16,18 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
1616 private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService . VALUES_DIRNAME + "-v" ;
1717 private static ANDROID_PLATFORM_NAME = "android" ;
1818 private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.3.0" ;
19+ private static MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS = "4.2.1" ;
20+ private static REQUIRED_DEV_DEPENDENCIES = [
21+ { name : "babel-traverse" , version : "^6.4.5" } ,
22+ { name : "babel-types" , version : "^6.4.5" } ,
23+ { name : "babylon" , version : "^6.4.5" } ,
24+ { name : "filewalker" , version : "^0.1.2" } ,
25+ { name : "lazy" , version : "^1.0.11" }
26+ ] ;
27+
28+ private get sysInfoData ( ) : ISysInfoData {
29+ return this . $sysInfo . getSysInfo ( path . join ( __dirname , ".." , ".." , "package.json" ) ) . wait ( ) ;
30+ }
1931
2032 private _androidProjectPropertiesManagers : IDictionary < IAndroidProjectPropertiesManager > ;
2133
@@ -36,7 +48,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
3648 private $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ,
3749 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
3850 private $projectTemplatesService : IProjectTemplatesService ,
39- private $xmlValidator : IXmlValidator ) {
51+ private $xmlValidator : IXmlValidator ,
52+ private $npm : INodePackageManager ) {
4053 super ( $fs , $projectData , $projectDataService ) ;
4154 this . _androidProjectPropertiesManagers = Object . create ( null ) ;
4255 }
@@ -88,7 +101,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
88101
89102 // this call will fail in case `android` is not set correctly.
90103 this . $androidToolsInfo . getPathToAndroidExecutable ( { showWarningsAsErrors : true } ) . wait ( ) ;
91- this . $androidToolsInfo . validateJavacVersion ( this . $sysInfo . getSysInfo ( path . join ( __dirname , ".." , ".." , "package.json" ) ) . wait ( ) . javacVersion , { showWarningsAsErrors : true } ) . wait ( ) ;
104+ this . $androidToolsInfo . validateJavacVersion ( this . sysInfoData . javacVersion , { showWarningsAsErrors : true } ) . wait ( ) ;
92105 } ) . future < void > ( ) ( ) ;
93106 }
94107
@@ -126,10 +139,28 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
126139 }
127140
128141 this . cleanResValues ( targetSdkVersion , frameworkVersion ) . wait ( ) ;
129-
142+ if ( this . canUseStaticBindingGenerator ( ) ) {
143+ let npmConfig = {
144+ "save" : true ,
145+ "save-dev" : true ,
146+ "save-exact" : true ,
147+ "silent" : true
148+ } ;
149+
150+ _ . each ( AndroidProjectService . REQUIRED_DEV_DEPENDENCIES , ( dependency : any ) =>
151+ this . $npm . install ( `${ dependency . name } @${ dependency . version } ` , this . $projectData . projectDir , npmConfig ) . wait ( )
152+ ) ;
153+ } else {
154+ this . $logger . printMarkdown ( ` As you are using Node.js \`${ this . sysInfoData . nodeVer } \` Static Binding Generator will be turned off.` +
155+ `Upgrade your Node.js to ${ AndroidProjectService . MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS } or later, so you can use this feature.` ) ;
156+ }
130157 } ) . future < any > ( ) ( ) ;
131158 }
132159
160+ private canUseStaticBindingGenerator ( ) : boolean {
161+ return semver . gte ( this . sysInfoData . nodeVer , AndroidProjectService . MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS ) ;
162+ }
163+
133164 private useGradleWrapper ( frameworkDir : string ) : boolean {
134165 let gradlew = path . join ( frameworkDir , "gradlew" ) ;
135166 return this . $fs . exists ( gradlew ) . wait ( ) ;
@@ -231,8 +262,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
231262 buildOptions . push ( `-PksPassword=${ this . $options . keyStorePassword } ` ) ;
232263 }
233264
234- if ( buildConfig && buildConfig . runSbGenerator ) {
235- buildOptions . push ( "-PrunSBGenerator " ) ;
265+ if ( ! this . canUseStaticBindingGenerator ( ) ) {
266+ buildOptions . push ( "-PdontRunSbg " ) ;
236267 }
237268
238269 let gradleBin = this . useGradleWrapper ( projectRoot ) ? path . join ( projectRoot , "gradlew" ) : "gradle" ;
0 commit comments