@@ -16,6 +16,23 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
16
16
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService . VALUES_DIRNAME + "-v" ;
17
17
private static ANDROID_PLATFORM_NAME = "android" ;
18
18
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 _sysInfoData : ISysInfoData ;
29
+ private get sysInfoData ( ) : ISysInfoData {
30
+ if ( ! this . _sysInfoData ) {
31
+ this . _sysInfoData = this . $sysInfo . getSysInfo ( path . join ( __dirname , ".." , ".." , "package.json" ) ) . wait ( ) ;
32
+ }
33
+
34
+ return this . _sysInfoData ;
35
+ }
19
36
20
37
private _androidProjectPropertiesManagers : IDictionary < IAndroidProjectPropertiesManager > ;
21
38
@@ -36,7 +53,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
36
53
private $deviceAppDataFactory : Mobile . IDeviceAppDataFactory ,
37
54
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
38
55
private $projectTemplatesService : IProjectTemplatesService ,
39
- private $xmlValidator : IXmlValidator ) {
56
+ private $xmlValidator : IXmlValidator ,
57
+ private $npm : INodePackageManager ) {
40
58
super ( $fs , $projectData , $projectDataService ) ;
41
59
this . _androidProjectPropertiesManagers = Object . create ( null ) ;
42
60
}
@@ -88,7 +106,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
88
106
89
107
// this call will fail in case `android` is not set correctly.
90
108
this . $androidToolsInfo . getPathToAndroidExecutable ( { showWarningsAsErrors : true } ) . wait ( ) ;
91
- this . $androidToolsInfo . validateJavacVersion ( this . $sysInfo . getSysInfo ( path . join ( __dirname , ".." , ".." , "package.json" ) ) . wait ( ) . javacVersion , { showWarningsAsErrors : true } ) . wait ( ) ;
109
+ this . $androidToolsInfo . validateJavacVersion ( this . sysInfoData . javacVersion , { showWarningsAsErrors : true } ) . wait ( ) ;
92
110
} ) . future < void > ( ) ( ) ;
93
111
}
94
112
@@ -126,10 +144,28 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
126
144
}
127
145
128
146
this . cleanResValues ( targetSdkVersion , frameworkVersion ) . wait ( ) ;
129
-
147
+ if ( this . canUseStaticBindingGenerator ( ) ) {
148
+ let npmConfig = {
149
+ "save" : true ,
150
+ "save-dev" : true ,
151
+ "save-exact" : true ,
152
+ "silent" : true
153
+ } ;
154
+
155
+ _ . each ( AndroidProjectService . REQUIRED_DEV_DEPENDENCIES , ( dependency : any ) =>
156
+ this . $npm . install ( `${ dependency . name } @${ dependency . version } ` , this . $projectData . projectDir , npmConfig ) . wait ( )
157
+ ) ;
158
+ } else {
159
+ this . $logger . printMarkdown ( `As you are using Node.js \`${ this . sysInfoData . nodeVer } \` Static Binding Generator will be turned off.
160
+ Upgrade your Node.js to ${ AndroidProjectService . MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS } or later, so you can use this feature.` ) ;
161
+ }
130
162
} ) . future < any > ( ) ( ) ;
131
163
}
132
164
165
+ private canUseStaticBindingGenerator ( ) : boolean {
166
+ return semver . gte ( this . sysInfoData . nodeVer , AndroidProjectService . MIN_REQUIRED_NODEJS_VERSION_FOR_STATIC_BINDINGS ) ;
167
+ }
168
+
133
169
private useGradleWrapper ( frameworkDir : string ) : boolean {
134
170
let gradlew = path . join ( frameworkDir , "gradlew" ) ;
135
171
return this . $fs . exists ( gradlew ) . wait ( ) ;
@@ -231,8 +267,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
231
267
buildOptions . push ( `-PksPassword=${ this . $options . keyStorePassword } ` ) ;
232
268
}
233
269
234
- if ( buildConfig && buildConfig . runSbGenerator ) {
235
- buildOptions . push ( "-PrunSBGenerator " ) ;
270
+ if ( ! this . canUseStaticBindingGenerator ( ) ) {
271
+ buildOptions . push ( "-PdontRunSbg " ) ;
236
272
}
237
273
238
274
let gradleBin = this . useGradleWrapper ( projectRoot ) ? path . join ( projectRoot , "gradlew" ) : "gradle" ;
0 commit comments