@@ -52,8 +52,6 @@ class AndroidProjectService implements IPlatformProjectService {
5252 return ( ( ) => {
5353 this . $fs . ensureDirectoryExists ( projectRoot ) . wait ( ) ;
5454
55- var newTarget = this . validateAndroidTarget ( frameworkDir ) ; // We need framework to be installed to validate android target so we can't call this method in validate()
56-
5755 if ( options . symlink ) {
5856 this . copy ( projectRoot , frameworkDir , "res" , "-R" ) . wait ( ) ;
5957 this . copy ( projectRoot , frameworkDir , ".project AndroidManifest.xml project.properties" , "-f" ) . wait ( ) ;
@@ -65,6 +63,7 @@ class AndroidProjectService implements IPlatformProjectService {
6563 this . copy ( projectRoot , frameworkDir , ".project AndroidManifest.xml project.properties" , "-f" ) . wait ( ) ;
6664 }
6765
66+ var newTarget = this . getLatestValidAndroidTarget ( frameworkDir ) . wait ( ) ;
6867 if ( newTarget ) {
6968 this . updateTarget ( projectRoot , newTarget ) . wait ( ) ;
7069 }
@@ -212,28 +211,21 @@ class AndroidProjectService implements IPlatformProjectService {
212211 }
213212 }
214213
215- private validateAndroidTarget ( frameworkDir : string ) : string {
216- var validTarget = this . getTarget ( frameworkDir ) . wait ( ) ;
217- var installedTargets = this . getInstalledTargets ( ) . wait ( ) ;
218- var newTarget : string = undefined ;
219- var match = _ . contains ( installedTargets , validTarget ) ;
220- if ( ! match ) {
214+ private getLatestValidAndroidTarget ( frameworkDir : string ) : IFuture < string > {
215+ return ( ( ) => {
216+ var validTarget = this . getTarget ( frameworkDir ) . wait ( ) ;
217+ var installedTargets = this . getInstalledTargets ( ) . wait ( ) ;
218+
221219 // adjust to the latest available version
222- newTarget = this . getCompatibleTarget ( ) ;
220+ var newTarget = _ ( this . SUPPORTED_TARGETS ) . sort ( ) . findLast ( supportedTarget => _ . contains ( installedTargets , supportedTarget ) ) ;
223221 if ( ! newTarget ) {
224222 this . $errors . fail ( "Please install Android target %s. Make sure you have the latest Android tools installed as well." +
225- " Run \"android\" from your command-line to install/update any missing SDKs or tools." ,
226- validTarget . split ( '-' ) [ 1 ] ) ;
223+ " Run \"android\" from your command-line to install/update any missing SDKs or tools." ,
224+ validTarget . split ( '-' ) [ 1 ] ) ;
227225 }
228- }
229226
230- return newTarget ;
231- }
232-
233- private getCompatibleTarget ( ) : string {
234- var installedTargets = this . getInstalledTargets ( ) . wait ( ) ;
235- var compatibleTarget = _ ( this . SUPPORTED_TARGETS ) . sort ( ) . findLast ( supportedTarget => _ . contains ( installedTargets , supportedTarget ) ) ;
236- return compatibleTarget ;
227+ return newTarget ;
228+ } ) . future < string > ( ) ( ) ;
237229 }
238230
239231 private updateTarget ( projectRoot : string , newTarget : string ) : IFuture < void > {
0 commit comments