@@ -61,9 +61,9 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
61
61
return this . _platformData ;
62
62
}
63
63
64
- public getAppResourcesDestinationDirectoryPath ( ) : IFuture < string > {
64
+ public getAppResourcesDestinationDirectoryPath ( frameworkVersion ?: string ) : IFuture < string > {
65
65
return ( ( ) => {
66
- if ( this . canUseGradle ( ) . wait ( ) ) {
66
+ if ( this . canUseGradle ( frameworkVersion ) . wait ( ) ) {
67
67
return path . join ( this . platformData . projectRoot , "src" , "main" , "res" ) ;
68
68
}
69
69
@@ -81,40 +81,39 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
81
81
} ) . future < void > ( ) ( ) ;
82
82
}
83
83
84
- public createProject ( projectRoot : string , frameworkDir : string ) : IFuture < void > {
84
+ public createProject ( frameworkDir : string , frameworkVersion : string ) : IFuture < void > {
85
85
return ( ( ) => {
86
- let frameworkVersion = this . $fs . readJson ( path . join ( frameworkDir , "../" , "package.json" ) ) . wait ( ) . version ;
87
86
if ( semver . lt ( frameworkVersion , AndroidProjectService . MIN_RUNTIME_VERSION_WITH_GRADLE ) ) {
88
87
this . $errors . fail ( `The NativeScript CLI requires Android runtime ${ AndroidProjectService . MIN_RUNTIME_VERSION_WITH_GRADLE } or later to work properly.` ) ;
89
88
}
90
89
91
90
// TODO: Move these check to validate method once we do not support ant.
92
91
this . checkGradle ( ) . wait ( ) ;
93
92
94
- this . $fs . ensureDirectoryExists ( projectRoot ) . wait ( ) ;
93
+ this . $fs . ensureDirectoryExists ( this . platformData . projectRoot ) . wait ( ) ;
95
94
let androidToolsInfo = this . $androidToolsInfo . getToolsInfo ( ) . wait ( ) ;
96
- let newTarget = androidToolsInfo . targetSdkVersion ;
97
- this . $logger . trace ( `Using Android SDK '${ newTarget } '.` ) ;
95
+ let targetSdkVersion = androidToolsInfo . targetSdkVersion ;
96
+ this . $logger . trace ( `Using Android SDK '${ targetSdkVersion } '.` ) ;
98
97
if ( this . $options . symlink ) {
99
- this . symlinkDirectory ( "build-tools" , projectRoot , frameworkDir ) . wait ( ) ;
100
- this . symlinkDirectory ( "libs" , projectRoot , frameworkDir ) . wait ( ) ;
101
- this . symlinkDirectory ( "src" , projectRoot , frameworkDir ) . wait ( ) ;
98
+ this . symlinkDirectory ( "build-tools" , this . platformData . projectRoot , frameworkDir ) . wait ( ) ;
99
+ this . symlinkDirectory ( "libs" , this . platformData . projectRoot , frameworkDir ) . wait ( ) ;
100
+ this . symlinkDirectory ( "src" , this . platformData . projectRoot , frameworkDir ) . wait ( ) ;
102
101
103
- this . $fs . symlink ( path . join ( frameworkDir , "build.gradle" ) , path . join ( projectRoot , "build.gradle" ) ) . wait ( ) ;
104
- this . $fs . symlink ( path . join ( frameworkDir , "settings.gradle" ) , path . join ( projectRoot , "settings.gradle" ) ) . wait ( ) ;
102
+ this . $fs . symlink ( path . join ( frameworkDir , "build.gradle" ) , path . join ( this . platformData . projectRoot , "build.gradle" ) ) . wait ( ) ;
103
+ this . $fs . symlink ( path . join ( frameworkDir , "settings.gradle" ) , path . join ( this . platformData . projectRoot , "settings.gradle" ) ) . wait ( ) ;
105
104
} else {
106
- this . copy ( projectRoot , frameworkDir , "build-tools libs src" , "-R" ) ;
107
- this . copy ( projectRoot , frameworkDir , "build.gradle settings.gradle" , "-f" ) ;
105
+ this . copy ( this . platformData . projectRoot , frameworkDir , "build-tools libs src" , "-R" ) ;
106
+ this . copy ( this . platformData . projectRoot , frameworkDir , "build.gradle settings.gradle" , "-f" ) ;
108
107
}
109
108
110
- this . cleanResValues ( newTarget ) . wait ( ) ;
109
+ this . cleanResValues ( targetSdkVersion , frameworkVersion ) . wait ( ) ;
111
110
112
111
} ) . future < any > ( ) ( ) ;
113
112
}
114
113
115
- private cleanResValues ( versionNumber : number ) : IFuture < void > {
114
+ private cleanResValues ( targetSdkVersion : number , frameworkVersion : string ) : IFuture < void > {
116
115
return ( ( ) => {
117
- let resDestinationDir = this . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ;
116
+ let resDestinationDir = this . getAppResourcesDestinationDirectoryPath ( frameworkVersion ) . wait ( ) ;
118
117
let directoriesInResFolder = this . $fs . readDirectory ( resDestinationDir ) . wait ( ) ;
119
118
let directoriesToClean = directoriesInResFolder
120
119
. map ( dir => { return {
@@ -124,7 +123,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
124
123
} )
125
124
. filter ( dir => dir . dirName . match ( AndroidProjectService . VALUES_VERSION_DIRNAME_PREFIX )
126
125
&& dir . sdkNum
127
- && ( ! versionNumber || ( versionNumber < dir . sdkNum ) ) )
126
+ && ( ! targetSdkVersion || ( targetSdkVersion < dir . sdkNum ) ) )
128
127
. map ( dir => path . join ( resDestinationDir , dir . dirName ) ) ;
129
128
this . $logger . trace ( "Directories to clean:" ) ;
130
129
this . $logger . trace ( directoriesToClean ) ;
@@ -270,11 +269,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
270
269
return Future . fromResult ( ) ;
271
270
}
272
271
273
- private canUseGradle ( ) : IFuture < boolean > {
272
+ private _canUseGradle : boolean ;
273
+ private canUseGradle ( frameworkVersion ?: string ) : IFuture < boolean > {
274
274
return ( ( ) => {
275
- this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
276
- let frameworkVersion = this . $projectDataService . getValue ( this . platformData . frameworkPackageName ) . wait ( ) . version ;
277
- return semver . gte ( frameworkVersion , AndroidProjectService . MIN_RUNTIME_VERSION_WITH_GRADLE ) ;
275
+ if ( ! this . _canUseGradle ) {
276
+ if ( ! frameworkVersion ) {
277
+ this . $projectDataService . initialize ( this . $projectData . projectDir ) ;
278
+ frameworkVersion = this . $projectDataService . getValue ( this . platformData . frameworkPackageName ) . wait ( ) . version ;
279
+ }
280
+
281
+ this . _canUseGradle = semver . gte ( frameworkVersion , AndroidProjectService . MIN_RUNTIME_VERSION_WITH_GRADLE ) ;
282
+ }
283
+
284
+ return this . _canUseGradle ;
278
285
} ) . future < boolean > ( ) ( ) ;
279
286
}
280
287
0 commit comments