@@ -61,9 +61,9 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
6161 return this . _platformData ;
6262 }
6363
64- public getAppResourcesDestinationDirectoryPath ( ) : IFuture < string > {
64+ public getAppResourcesDestinationDirectoryPath ( frameworkVersion ?: string ) : IFuture < string > {
6565 return ( ( ) => {
66- if ( this . canUseGradle ( ) . wait ( ) ) {
66+ if ( this . canUseGradle ( frameworkVersion ) . wait ( ) ) {
6767 return path . join ( this . platformData . projectRoot , "src" , "main" , "res" ) ;
6868 }
6969
@@ -81,40 +81,39 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
8181 } ) . future < void > ( ) ( ) ;
8282 }
8383
84- public createProject ( projectRoot : string , frameworkDir : string ) : IFuture < void > {
84+ public createProject ( frameworkDir : string , frameworkVersion : string ) : IFuture < void > {
8585 return ( ( ) => {
86- let frameworkVersion = this . $fs . readJson ( path . join ( frameworkDir , "../" , "package.json" ) ) . wait ( ) . version ;
8786 if ( semver . lt ( frameworkVersion , AndroidProjectService . MIN_RUNTIME_VERSION_WITH_GRADLE ) ) {
8887 this . $errors . fail ( `The NativeScript CLI requires Android runtime ${ AndroidProjectService . MIN_RUNTIME_VERSION_WITH_GRADLE } or later to work properly.` ) ;
8988 }
9089
9190 // TODO: Move these check to validate method once we do not support ant.
9291 this . checkGradle ( ) . wait ( ) ;
9392
94- this . $fs . ensureDirectoryExists ( projectRoot ) . wait ( ) ;
93+ this . $fs . ensureDirectoryExists ( this . platformData . projectRoot ) . wait ( ) ;
9594 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 } '.` ) ;
9897 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 ( ) ;
102101
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 ( ) ;
105104 } 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" ) ;
108107 }
109108
110- this . cleanResValues ( newTarget ) . wait ( ) ;
109+ this . cleanResValues ( targetSdkVersion , frameworkVersion ) . wait ( ) ;
111110
112111 } ) . future < any > ( ) ( ) ;
113112 }
114113
115- private cleanResValues ( versionNumber : number ) : IFuture < void > {
114+ private cleanResValues ( targetSdkVersion : number , frameworkVersion : string ) : IFuture < void > {
116115 return ( ( ) => {
117- let resDestinationDir = this . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ;
116+ let resDestinationDir = this . getAppResourcesDestinationDirectoryPath ( frameworkVersion ) . wait ( ) ;
118117 let directoriesInResFolder = this . $fs . readDirectory ( resDestinationDir ) . wait ( ) ;
119118 let directoriesToClean = directoriesInResFolder
120119 . map ( dir => { return {
@@ -124,7 +123,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
124123 } )
125124 . filter ( dir => dir . dirName . match ( AndroidProjectService . VALUES_VERSION_DIRNAME_PREFIX )
126125 && dir . sdkNum
127- && ( ! versionNumber || ( versionNumber < dir . sdkNum ) ) )
126+ && ( ! targetSdkVersion || ( targetSdkVersion < dir . sdkNum ) ) )
128127 . map ( dir => path . join ( resDestinationDir , dir . dirName ) ) ;
129128 this . $logger . trace ( "Directories to clean:" ) ;
130129 this . $logger . trace ( directoriesToClean ) ;
@@ -270,11 +269,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
270269 return Future . fromResult ( ) ;
271270 }
272271
273- private canUseGradle ( ) : IFuture < boolean > {
272+ private _canUseGradle : boolean ;
273+ private canUseGradle ( frameworkVersion ?: string ) : IFuture < boolean > {
274274 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 ;
278285 } ) . future < boolean > ( ) ( ) ;
279286 }
280287
0 commit comments