@@ -206,24 +206,35 @@ task pluginStructureCheck {
206
206
}
207
207
}
208
208
209
- def createProductFlavorsContent (flavor , dimensionName )
209
+ def createProductFlavorsContent (flavor , dimensionName , includeAndroidContent = true )
210
210
{
211
- def content = """ android {
212
- productFlavors {
213
- ${ flavor} {
214
- dimension ${ dimensionName}
215
- }
216
- }
217
- }"""
218
- return content;
211
+ if (includeAndroidContent)
212
+ {
213
+ def content = """ android {
214
+ productFlavors {
215
+ "${ flavor} " {
216
+ dimension "${ dimensionName} "
217
+ }
218
+ }
219
+ }"""
220
+ return content;
221
+ }
222
+ else
223
+ {
224
+ def content = """ productFlavors {
225
+ "${ flavor} " {
226
+ dimension "${ dimensionName} "
227
+ }
228
+ }"""
229
+ return content;
230
+ }
219
231
}
220
232
221
233
222
234
def createIncludeFile (filePath , flavor , dimensionName ) {
223
235
println " \t + creating include.gradle file for ${ filePath} "
224
236
225
237
def defaultIncludeFile = new File (filePath, " include.gradle" )
226
-
227
238
defaultIncludeFiletext. text = createProductFlavorsContent(flavor, dimensionName);
228
239
}
229
240
@@ -265,20 +276,23 @@ def replaceProductFlavorInContent(content, dimension, flavor)
265
276
{
266
277
def oldProductFlavorsText = content. substring(indexStart, indexEnd - 1 );
267
278
268
- def newProductFlavorsText = """
269
- productFlavors {
270
- "${ flavor} " {
271
- dimension "${ dimension} "
272
- }
273
- }
274
- """ ;
279
+ def newProductFlavorsContent = createProductFlavorsContent(flavor, dimension, false );
275
280
276
- return content. replace(oldProductFlavorsText, newProductFlavorsText );
281
+ return content. replace(oldProductFlavorsText, newProductFlavorsContent );
277
282
}
278
283
else
279
284
{
280
- def newProductFlavorsContent = createProductFlavorsContent(flavor, dimension);
281
- return content. replace(" android {" , " android {\t ${ newProductFlavorsContent} " );
285
+ def androidContentExists = content. indexOf(" android {" ) != -1 ;
286
+ def newProductFlavorsContent = createProductFlavorsContent(flavor, dimension, ! androidContentExists);
287
+
288
+ if (androidContentExists)
289
+ {
290
+ return content. replace(" android {" , " android { ${ newProductFlavorsContent} " );
291
+ }
292
+ else
293
+ {
294
+ return " ${ newProductFlavorsContent} \t ${ content} "
295
+ }
282
296
}
283
297
}
284
298
@@ -333,17 +347,16 @@ task createPluginsConfigFile {
333
347
println " $configStage createPluginsConfigFile"
334
348
335
349
def flavorsFile = new File (" $configurationsDir /include.gradle" )
336
- flavorsFile. write " " // clear config file
337
-
350
+
338
351
if (createPluginConfigFile) {
339
- println " \t +creating product flavors include.gradle file in $configurationsDir folder..."
352
+ println " \t Creating product flavors include.gradle file in $configurationsDir folder..."
340
353
def flavors = flavorNames. join(" , " )
341
354
342
355
def content = """ android {
343
356
flavorDimensions ${ flavors}
344
357
}"""
345
358
346
- flavorsFile << content
359
+ flavorsFile. text = content
347
360
}
348
361
}
349
362
}
0 commit comments