@@ -8,6 +8,8 @@ import * as semver from "semver";
8
8
import * as projectServiceBaseLib from "./platform-project-service-base" ;
9
9
import * as androidDebugBridgePath from "../common/mobile/android/android-debug-bridge" ;
10
10
import { AndroidDeviceHashService } from "../common/mobile/android/android-device-hash-service" ;
11
+ import { EOL } from "os" ;
12
+ import { createGUID } from "../common/helpers" ;
11
13
12
14
export class AndroidProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
13
15
private static VALUES_DIRNAME = "values" ;
@@ -233,12 +235,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
233
235
}
234
236
this . spawn ( gradleBin , buildOptions , { stdio : "inherit" , cwd : this . platformData . projectRoot } ) . wait ( ) ;
235
237
} else {
236
- this . checkAnt ( ) . wait ( ) ;
237
-
238
- let args = this . getAntArgs ( this . $options . release ? "release" : "debug" , projectRoot ) ;
239
- this . spawn ( 'ant' , args ) . wait ( ) ;
240
-
241
- this . platformData . deviceBuildOutputPath = path . join ( this . platformData . projectRoot , "bin" ) ;
238
+ this . $errors . failWithoutHelp ( "Cannot complete build because this project is ANT-based." + EOL +
239
+ "Run `tns platform remove android && tns platform add android` to switch to Gradle and try again." ) ;
242
240
}
243
241
} ) . future < void > ( ) ( ) ;
244
242
}
@@ -274,31 +272,14 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
274
272
return ( ( ) => {
275
273
let originalAndroidManifestFilePath = path . join ( this . $projectData . appResourcesDirectoryPath , this . $devicePlatformsConstants . Android , this . platformData . configurationFileName ) ,
276
274
hasAndroidManifestInAppResources = this . $fs . exists ( originalAndroidManifestFilePath ) . wait ( ) ,
277
- shouldExtractDefaultManifest = ! hasAndroidManifestInAppResources ,
278
- isAndroidManifestBackedUp = false ;
279
-
280
- if ( hasAndroidManifestInAppResources ) {
281
- let isFileCorrect = this . isAndroidManifestFileCorrect ( originalAndroidManifestFilePath ) . wait ( ) ;
282
- if ( ! isFileCorrect ) {
283
- shouldExtractDefaultManifest = true ;
284
- isAndroidManifestBackedUp = true ;
285
- this . backupOriginalAndroidManifest ( originalAndroidManifestFilePath ) . wait ( ) ;
286
- }
287
- }
275
+ shouldExtractDefaultManifest = ! hasAndroidManifestInAppResources || ! this . isAndroidManifestFileCorrect ( originalAndroidManifestFilePath ) . wait ( ) ;
288
276
289
277
// In case we should extract the manifest from default template, but for some reason we cannot, break the execution,
290
278
// so the original file from Android runtime will be used.
291
279
if ( shouldExtractDefaultManifest && ! this . extractAndroidManifestFromDefaultTemplate ( originalAndroidManifestFilePath ) . wait ( ) ) {
292
- // now revert back
293
- this . revertBackupOfOriginalAndroidManifest ( originalAndroidManifestFilePath ) . wait ( ) ;
294
280
return ;
295
281
}
296
282
297
- if ( isAndroidManifestBackedUp ) {
298
- this . $logger . warn ( `Your ${ this . platformData . configurationFileName } in app/App_Resources/Android will be replaced by the default one from hello-world template.` ) ;
299
- this . $logger . printMarkdown ( `The original file will be moved to \`${ this . configurationFileBackupName } \`. Merge it **manually** with the new \`${ this . platformData . configurationFileName } \` in your app/App_Resources/Android.` ) ;
300
- }
301
-
302
283
// Overwrite the AndroidManifest from runtime.
303
284
this . $fs . copyFile ( originalAndroidManifestFilePath , this . platformData . configurationFilePath ) . wait ( ) ;
304
285
} ) . future < void > ( ) ( ) ;
@@ -416,32 +397,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
416
397
return this . $childProcess . spawnFromEvent ( command , args , "close" , opts || { stdio : "inherit" } ) ;
417
398
}
418
399
419
- private getAntArgs ( configuration : string , projectRoot : string ) : string [ ] {
420
- let args = [ configuration , "-f" , path . join ( projectRoot , "build.xml" ) ] ;
421
- if ( configuration === "release" ) {
422
- if ( this . $options . keyStorePath ) {
423
- args = args . concat ( [ "-Dkey.store" , path . resolve ( this . $options . keyStorePath ) ] ) ;
424
- }
425
-
426
- if ( this . $options . keyStorePassword ) {
427
- args = args . concat ( [ "-Dkey.store.password" , this . $options . keyStorePassword ] ) ;
428
- }
429
-
430
- if ( this . $options . keyStoreAlias ) {
431
- args = args . concat ( [ "-Dkey.alias" , this . $options . keyStoreAlias ] ) ;
432
- }
433
-
434
- if ( this . $options . keyStoreAliasPassword ) {
435
- args = args . concat ( [ "-Dkey.alias.password" , this . $options . keyStoreAliasPassword ] ) ;
436
- }
437
- }
438
-
439
- // metadata generation support
440
- args = args . concat ( [ "-Dns.resources" , path . join ( __dirname , "../../resources/tools" ) ] ) ;
441
-
442
- return args ;
443
- }
444
-
445
400
private validatePackageName ( packageName : string ) : void {
446
401
//Make the package conform to Java package types
447
402
//Enforce underscore limitation
@@ -483,16 +438,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
483
438
} ) . future < string > ( ) ( ) ;
484
439
}
485
440
486
- private checkAnt ( ) : IFuture < void > {
487
- return ( ( ) => {
488
- try {
489
- this . $childProcess . exec ( "ant -version" ) . wait ( ) ;
490
- } catch ( error ) {
491
- this . $errors . fail ( "Error executing commands 'ant', make sure you have ant installed and added to your PATH." ) ;
492
- }
493
- } ) . future < void > ( ) ( ) ;
494
- }
495
-
496
441
private symlinkDirectory ( directoryName : string , projectRoot : string , frameworkDir : string ) : IFuture < void > {
497
442
return ( ( ) => {
498
443
this . $fs . createDirectory ( path . join ( projectRoot , directoryName ) ) . wait ( ) ;
@@ -533,20 +478,32 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
533
478
} ) . future < boolean > ( ) ( ) ;
534
479
}
535
480
536
- private get configurationFileBackupName ( ) : string {
537
- return this . platformData . configurationFileName + ".backup" ;
481
+ private _configurationFileBackupName : string ;
482
+
483
+ private getConfigurationFileBackupName ( originalAndroidManifestFilePath : string ) : IFuture < string > {
484
+ return ( ( ) => {
485
+ if ( ! this . _configurationFileBackupName ) {
486
+ let defaultBackupName = this . platformData . configurationFileName + ".backup" ;
487
+ if ( this . $fs . exists ( path . join ( path . dirname ( originalAndroidManifestFilePath ) , defaultBackupName ) ) . wait ( ) ) {
488
+ defaultBackupName += `_${ createGUID ( false ) } ` ;
489
+ }
490
+ this . _configurationFileBackupName = defaultBackupName ;
491
+ }
492
+
493
+ return this . _configurationFileBackupName ;
494
+ } ) . future < string > ( ) ( ) ;
538
495
}
539
496
540
497
private backupOriginalAndroidManifest ( originalAndroidManifestFilePath : string ) : IFuture < void > {
541
498
return ( ( ) => {
542
- let newPathForOriginalManifest = path . join ( path . dirname ( originalAndroidManifestFilePath ) , this . configurationFileBackupName ) ;
499
+ let newPathForOriginalManifest = path . join ( path . dirname ( originalAndroidManifestFilePath ) , this . getConfigurationFileBackupName ( originalAndroidManifestFilePath ) . wait ( ) ) ;
543
500
shell . mv ( originalAndroidManifestFilePath , newPathForOriginalManifest ) ;
544
501
} ) . future < void > ( ) ( ) ;
545
502
}
546
503
547
504
private revertBackupOfOriginalAndroidManifest ( originalAndroidManifestFilePath : string ) : IFuture < void > {
548
505
return ( ( ) => {
549
- let pathToBackupFile = path . join ( path . dirname ( originalAndroidManifestFilePath ) , this . configurationFileBackupName ) ;
506
+ let pathToBackupFile = path . join ( path . dirname ( originalAndroidManifestFilePath ) , this . getConfigurationFileBackupName ( originalAndroidManifestFilePath ) . wait ( ) ) ;
550
507
if ( this . $fs . exists ( pathToBackupFile ) . wait ( ) ) {
551
508
this . $logger . trace ( `Could not extract ${ this . platformData . configurationFileName } from default template. Reverting the change of your app/App_Resources/${ this . platformData . configurationFileName } .` ) ;
552
509
shell . mv ( pathToBackupFile , originalAndroidManifestFilePath ) ;
@@ -558,19 +515,29 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
558
515
return ( ( ) : boolean => {
559
516
let defaultTemplatePath = this . $projectTemplatesService . defaultTemplatePath . wait ( ) ;
560
517
let templateAndroidManifest = path . join ( defaultTemplatePath , constants . APP_RESOURCES_FOLDER_NAME , this . $devicePlatformsConstants . Android , this . platformData . configurationFileName ) ;
518
+ let alreadyHasAndroidManifest = this . $fs . exists ( originalAndroidManifestFilePath ) . wait ( ) ;
561
519
if ( this . $fs . exists ( templateAndroidManifest ) . wait ( ) ) {
562
520
this . $logger . trace ( `${ originalAndroidManifestFilePath } is missing. Upgrading the source of the project with one from the new project template. Copy ${ templateAndroidManifest } to ${ originalAndroidManifestFilePath } ` ) ;
563
521
try {
522
+ if ( alreadyHasAndroidManifest ) {
523
+ this . backupOriginalAndroidManifest ( originalAndroidManifestFilePath ) . wait ( ) ;
524
+ }
564
525
this . $fs . copyFile ( templateAndroidManifest , originalAndroidManifestFilePath ) . wait ( ) ;
565
526
} catch ( e ) {
566
527
this . $logger . trace ( `Copying template's ${ this . platformData . configurationFileName } failed. ` , e ) ;
528
+ this . revertBackupOfOriginalAndroidManifest ( originalAndroidManifestFilePath ) . wait ( ) ;
567
529
return false ;
568
530
}
569
531
} else {
570
532
this . $logger . trace ( `${ originalAndroidManifestFilePath } is missing but the template ${ templateAndroidManifest } is missing too, can not upgrade ${ this . platformData . configurationFileName } .` ) ;
571
533
return false ;
572
534
}
573
535
536
+ if ( alreadyHasAndroidManifest ) {
537
+ this . $logger . warn ( `Your ${ this . platformData . configurationFileName } in app/App_Resources/Android will be replaced by the default one from hello-world template.` ) ;
538
+ this . $logger . printMarkdown ( `The original file will be moved to \`${ this . getConfigurationFileBackupName ( originalAndroidManifestFilePath ) . wait ( ) } \`. Merge it **manually** with the new \`${ this . platformData . configurationFileName } \` in your app/App_Resources/Android.` ) ;
539
+ }
540
+
574
541
this . interpolateConfigurationFile ( ) . wait ( ) ;
575
542
return true ;
576
543
} ) . future < boolean > ( ) ( ) ;
0 commit comments