@@ -25,14 +25,18 @@ export class PlatformController implements IPlatformController {
2525 private $packageInstallationManager : IPackageInstallationManager ,
2626 private $projectDataService : IProjectDataService ,
2727 private $platformsDataService : IPlatformsDataService ,
28- private $projectChangesService : IProjectChangesService
28+ private $projectChangesService : IProjectChangesService ,
29+ private $mobileHelper : Mobile . IMobileHelper
2930 ) { }
3031
31- public async addPlatform ( addPlatformData : IAddPlatformData ) : Promise < void > {
32+ public async addPlatform (
33+ addPlatformData : IAddPlatformData ,
34+ projectData ?: IProjectData
35+ ) : Promise < void > {
3236 const [ platform , version ] = addPlatformData . platform
3337 . toLowerCase ( )
3438 . split ( "@" ) ;
35- const projectData = this . $projectDataService . getProjectData (
39+ projectData ?? = this . $projectDataService . getProjectData (
3640 addPlatformData . projectDir
3741 ) ;
3842 const platformData = this . $platformsDataService . getPlatformData (
@@ -68,18 +72,54 @@ export class PlatformController implements IPlatformController {
6872 this . $fs . ensureDirectoryExists (
6973 path . join ( projectData . platformsDir , platform )
7074 ) ;
75+
76+ if ( this . $mobileHelper . isAndroidPlatform ( platform ) ) {
77+ const gradlePropertiesPath = path . resolve (
78+ platformData . projectRoot ,
79+ "gradle.properties"
80+ ) ;
81+ const commentHeader = "# App configuration" ;
82+ const appPath = projectData . getAppDirectoryRelativePath ( ) ;
83+ const appResourcesPath = projectData . getAppResourcesRelativeDirectoryPath ( ) ;
84+
85+ let gradlePropertiesContents = "" ;
86+ if ( this . $fs . exists ( gradlePropertiesPath ) ) {
87+ gradlePropertiesContents = this . $fs
88+ . readFile ( gradlePropertiesPath )
89+ . toString ( ) ;
90+ }
91+
92+ if ( ! gradlePropertiesContents . includes ( commentHeader ) ) {
93+ const dataToWrite = [
94+ "" ,
95+ "" ,
96+ commentHeader ,
97+ `appPath = ${ appPath } ` ,
98+ `appResourcesPath = ${ appResourcesPath } ` ,
99+ "" ,
100+ ] . join ( "\n" ) ;
101+
102+ gradlePropertiesContents += dataToWrite ;
103+
104+ this . $logger . trace ( "Updated gradle.properties with project data..." ) ;
105+ this . $fs . writeFile ( gradlePropertiesPath , gradlePropertiesContents ) ;
106+ }
107+ }
71108 this . $logger . info (
72109 `Platform ${ platform } successfully added. v${ installedPlatformVersion } `
73110 ) ;
74111 }
75112
76113 public async addPlatformIfNeeded (
77- addPlatformData : IAddPlatformData
114+ addPlatformData : IAddPlatformData ,
115+ projectData ?: IProjectData
78116 ) : Promise < void > {
79117 const [ platform ] = addPlatformData . platform . toLowerCase ( ) . split ( "@" ) ;
80- const projectData = this . $projectDataService . getProjectData (
118+
119+ projectData ??= this . $projectDataService . getProjectData (
81120 addPlatformData . projectDir
82121 ) ;
122+
83123 const platformData = this . $platformsDataService . getPlatformData (
84124 platform ,
85125 projectData
@@ -91,7 +131,7 @@ export class PlatformController implements IPlatformController {
91131 addPlatformData . nativePrepare
92132 ) ;
93133 if ( shouldAddPlatform ) {
94- await this . addPlatform ( addPlatformData ) ;
134+ await this . addPlatform ( addPlatformData , projectData ) ;
95135 }
96136 }
97137
0 commit comments