@@ -25,14 +25,18 @@ export class PlatformController implements IPlatformController {
25
25
private $packageInstallationManager : IPackageInstallationManager ,
26
26
private $projectDataService : IProjectDataService ,
27
27
private $platformsDataService : IPlatformsDataService ,
28
- private $projectChangesService : IProjectChangesService
28
+ private $projectChangesService : IProjectChangesService ,
29
+ private $mobileHelper : Mobile . IMobileHelper
29
30
) { }
30
31
31
- public async addPlatform ( addPlatformData : IAddPlatformData ) : Promise < void > {
32
+ public async addPlatform (
33
+ addPlatformData : IAddPlatformData ,
34
+ projectData ?: IProjectData
35
+ ) : Promise < void > {
32
36
const [ platform , version ] = addPlatformData . platform
33
37
. toLowerCase ( )
34
38
. split ( "@" ) ;
35
- const projectData = this . $projectDataService . getProjectData (
39
+ projectData ?? = this . $projectDataService . getProjectData (
36
40
addPlatformData . projectDir
37
41
) ;
38
42
const platformData = this . $platformsDataService . getPlatformData (
@@ -68,18 +72,54 @@ export class PlatformController implements IPlatformController {
68
72
this . $fs . ensureDirectoryExists (
69
73
path . join ( projectData . platformsDir , platform )
70
74
) ;
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
+ }
71
108
this . $logger . info (
72
109
`Platform ${ platform } successfully added. v${ installedPlatformVersion } `
73
110
) ;
74
111
}
75
112
76
113
public async addPlatformIfNeeded (
77
- addPlatformData : IAddPlatformData
114
+ addPlatformData : IAddPlatformData ,
115
+ projectData ?: IProjectData
78
116
) : Promise < void > {
79
117
const [ platform ] = addPlatformData . platform . toLowerCase ( ) . split ( "@" ) ;
80
- const projectData = this . $projectDataService . getProjectData (
118
+
119
+ projectData ??= this . $projectDataService . getProjectData (
81
120
addPlatformData . projectDir
82
121
) ;
122
+
83
123
const platformData = this . $platformsDataService . getPlatformData (
84
124
platform ,
85
125
projectData
@@ -91,7 +131,7 @@ export class PlatformController implements IPlatformController {
91
131
addPlatformData . nativePrepare
92
132
) ;
93
133
if ( shouldAddPlatform ) {
94
- await this . addPlatform ( addPlatformData ) ;
134
+ await this . addPlatform ( addPlatformData , projectData ) ;
95
135
}
96
136
}
97
137
0 commit comments