@@ -7,7 +7,6 @@ import * as projectServiceBaseLib from "./platform-project-service-base";
77import { DeviceAndroidDebugBridge } from "../common/mobile/android/device-android-debug-bridge" ;
88import { AndroidDeviceHashService } from "../common/mobile/android/android-device-hash-service" ;
99import { EOL } from "os" ;
10- import { createGUID } from "../common/helpers" ;
1110
1211export class AndroidProjectService extends projectServiceBaseLib . PlatformProjectServiceBase implements IPlatformProjectService {
1312 private static VALUES_DIRNAME = "values" ;
@@ -307,31 +306,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
307306 }
308307
309308 public prepareProject ( ) : IFuture < void > {
310- return ( ( ) => {
311- let resDestinationDir = this . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ;
312- let androidManifestPath = path . join ( resDestinationDir , this . platformData . configurationFileName ) ;
313-
314- // In case the file is not correct, looks like we are still using the default AndroidManifest.xml from runtime and the current file (in res dir)
315- // should be merged with it.
316- if ( this . isAndroidManifestFileCorrect ( androidManifestPath ) . wait ( ) ) {
317- // Delete the AndroidManifest.xml file from res directory as the runtime will consider it as addition to the one in src/main and will try to merge them.
318- // However now they are the same file.
319- this . $fs . deleteFile ( androidManifestPath ) . wait ( ) ;
320- }
321- } ) . future < void > ( ) ( ) ;
309+ return Future . fromResult ( ) ;
322310 }
323311
324312 public ensureConfigurationFileInAppResources ( ) : IFuture < void > {
325313 return ( ( ) => {
326- let originalAndroidManifestFilePath = path . join ( this . $projectData . appResourcesDirectoryPath , this . $devicePlatformsConstants . Android , this . platformData . configurationFileName ) ,
327- hasAndroidManifestInAppResources = this . $fs . exists ( originalAndroidManifestFilePath ) . wait ( ) ,
328- shouldExtractDefaultManifest = ! hasAndroidManifestInAppResources || ! this . isAndroidManifestFileCorrect ( originalAndroidManifestFilePath ) . wait ( ) ;
329-
330- // In case we should extract the manifest from default template, but for some reason we cannot, break the execution,
331- // so the original file from Android runtime will be used.
332- if ( shouldExtractDefaultManifest && ! this . extractAndroidManifestFromDefaultTemplate ( originalAndroidManifestFilePath ) . wait ( ) ) {
333- return ;
334- }
314+ let originalAndroidManifestFilePath = path . join ( this . $projectData . appResourcesDirectoryPath , this . $devicePlatformsConstants . Android , this . platformData . configurationFileName ) ;
335315
336316 // Overwrite the AndroidManifest from runtime.
337317 this . $fs . copyFile ( originalAndroidManifestFilePath , this . platformData . configurationFilePath ) . wait ( ) ;
@@ -526,101 +506,5 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
526506
527507 } ) . future < void > ( ) ( ) ;
528508 }
529-
530- private isAndroidManifestFileCorrect ( pathToAndroidManifest : string ) : IFuture < boolean > {
531- return ( ( ) : boolean => {
532- try {
533- // Check if the AndroidManifest in app/App_Resouces is the correct one
534- // Use a real magic to detect if this is the correct file, by checking some mandatory strings.
535- let fileContent = this . $fs . readText ( pathToAndroidManifest ) . wait ( ) ,
536- isFileCorrect = ! ! ( ~ fileContent . indexOf ( "android:minSdkVersion" ) && ~ fileContent . indexOf ( "android:targetSdkVersion" )
537- && ~ fileContent . indexOf ( "uses-permission" ) && ~ fileContent . indexOf ( "<application" )
538- && ~ fileContent . indexOf ( "<activity" ) && ~ fileContent . indexOf ( "<intent-filter>" )
539- && ~ fileContent . indexOf ( "android.intent.action.MAIN" )
540- && ~ fileContent . indexOf ( "android:versionCode" )
541- && ! this . $xmlValidator . getXmlFileErrors ( pathToAndroidManifest ) . wait ( ) ) ;
542-
543- this . $logger . trace ( `Existing ${ this . platformData . configurationFileName } is ${ isFileCorrect ? "" : "NOT " } correct.` ) ;
544- return isFileCorrect ;
545- } catch ( err ) {
546- this . $logger . trace ( `Error while checking ${ pathToAndroidManifest } : ` , err ) ;
547- return false ;
548- }
549- } ) . future < boolean > ( ) ( ) ;
550- }
551-
552- private _configurationFileBackupName : string ;
553-
554- private getConfigurationFileBackupName ( originalAndroidManifestFilePath : string ) : IFuture < string > {
555- return ( ( ) => {
556- if ( ! this . _configurationFileBackupName ) {
557- let defaultBackupName = this . platformData . configurationFileName + ".backup" ;
558- if ( this . $fs . exists ( path . join ( path . dirname ( originalAndroidManifestFilePath ) , defaultBackupName ) ) . wait ( ) ) {
559- defaultBackupName += `_${ createGUID ( false ) } ` ;
560- }
561- this . _configurationFileBackupName = defaultBackupName ;
562- }
563-
564- return this . _configurationFileBackupName ;
565- } ) . future < string > ( ) ( ) ;
566- }
567-
568- private backupOriginalAndroidManifest ( originalAndroidManifestFilePath : string ) : IFuture < void > {
569- return ( ( ) => {
570- let newPathForOriginalManifest = path . join ( path . dirname ( originalAndroidManifestFilePath ) , this . getConfigurationFileBackupName ( originalAndroidManifestFilePath ) . wait ( ) ) ;
571- shell . mv ( originalAndroidManifestFilePath , newPathForOriginalManifest ) ;
572- } ) . future < void > ( ) ( ) ;
573- }
574-
575- private revertBackupOfOriginalAndroidManifest ( originalAndroidManifestFilePath : string ) : IFuture < void > {
576- return ( ( ) => {
577- let pathToBackupFile = path . join ( path . dirname ( originalAndroidManifestFilePath ) , this . getConfigurationFileBackupName ( originalAndroidManifestFilePath ) . wait ( ) ) ;
578- if ( this . $fs . exists ( pathToBackupFile ) . wait ( ) ) {
579- this . $logger . trace ( `Could not extract ${ this . platformData . configurationFileName } from default template. Reverting the change of your app/App_Resources/${ this . platformData . configurationFileName } .` ) ;
580- shell . mv ( pathToBackupFile , originalAndroidManifestFilePath ) ;
581- }
582- } ) . future < void > ( ) ( ) ;
583- }
584-
585- private extractAndroidManifestFromDefaultTemplate ( originalAndroidManifestFilePath : string ) : IFuture < boolean > {
586- return ( ( ) : boolean => {
587- let defaultTemplatePath = this . $projectTemplatesService . defaultTemplatePath . wait ( ) ;
588- let templateAndroidManifest = path . join ( defaultTemplatePath , constants . APP_RESOURCES_FOLDER_NAME , this . $devicePlatformsConstants . Android , this . platformData . configurationFileName ) ;
589- let alreadyHasAndroidManifest = this . $fs . exists ( originalAndroidManifestFilePath ) . wait ( ) ;
590- if ( this . $fs . exists ( templateAndroidManifest ) . wait ( ) ) {
591- this . $logger . trace ( `${ originalAndroidManifestFilePath } is missing. Upgrading the source of the project with one from the new project template. Copy ${ templateAndroidManifest } to ${ originalAndroidManifestFilePath } ` ) ;
592- try {
593- if ( alreadyHasAndroidManifest ) {
594- this . backupOriginalAndroidManifest ( originalAndroidManifestFilePath ) . wait ( ) ;
595- }
596-
597- let content = this . $fs . readText ( templateAndroidManifest ) . wait ( ) ;
598-
599- // We do not want to force launch screens on old projects.
600- let themeMeta = `<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />` ;
601- content = content
602- . replace ( `\n\t\t\tandroid:theme="@style/LaunchScreenTheme">\n` , `>\n\t\t\t<!-- android:theme="@style/LaunchScreenTheme" -->\n` )
603- . replace ( themeMeta , "<!-- " + themeMeta + " -->" ) ;
604-
605- this . $fs . writeFile ( originalAndroidManifestFilePath , content ) . wait ( ) ;
606- } catch ( e ) {
607- this . $logger . trace ( `Copying template's ${ this . platformData . configurationFileName } failed. ` , e ) ;
608- this . revertBackupOfOriginalAndroidManifest ( originalAndroidManifestFilePath ) . wait ( ) ;
609- return false ;
610- }
611- } else {
612- this . $logger . trace ( `${ originalAndroidManifestFilePath } is missing but the template ${ templateAndroidManifest } is missing too, can not upgrade ${ this . platformData . configurationFileName } .` ) ;
613- return false ;
614- }
615-
616- if ( alreadyHasAndroidManifest ) {
617- this . $logger . warn ( `Your ${ this . platformData . configurationFileName } in app/App_Resources/Android will be replaced by the default one from hello-world template.` ) ;
618- 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.` ) ;
619- }
620-
621- this . interpolateConfigurationFile ( ) . wait ( ) ;
622- return true ;
623- } ) . future < boolean > ( ) ( ) ;
624- }
625509}
626510$injector . register ( "androidProjectService" , AndroidProjectService ) ;
0 commit comments