Skip to content

Commit 691e56e

Browse files
committed
fix(project-build-script): fix the include gradle flavor generation logic
1 parent 34cf539 commit 691e56e

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

build-artifacts/project-template-gradle/app/build.gradle

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -349,43 +349,42 @@ static def sanitizeDimensionName(str) {
349349
}
350350

351351
static def modifyProductFlavorInContent(content, dimension, flavor) {
352-
def indexStart = content.indexOf("productFlavors");
353-
def index = indexStart + "productFlavors".length();
354-
def indexEnd = -1;
355-
def nestedOpenBracketsCount = 0;
356-
357-
while (index < content.length())
358-
{
359-
// print content[index];
360-
if (content[index] == "}")
361-
{
362-
nestedOpenBracketsCount--;
363-
364-
if (nestedOpenBracketsCount == 0)
365-
{
366-
indexEnd = index;
367-
break;
352+
def PRODUCT_FLAVORS = "productFlavors"
353+
def indexStart = content.indexOf(PRODUCT_FLAVORS)
354+
def index = indexStart + PRODUCT_FLAVORS.length()
355+
def indexEnd = -1
356+
def nestedOpenBracketsCount = 0
357+
358+
if (indexStart != -1) {
359+
// get the index of the closing bracket of the productFlavors { } scope
360+
while (index < content.length()) {
361+
// print content[index];
362+
if (content[index] == "}") {
363+
nestedOpenBracketsCount--
364+
365+
if (nestedOpenBracketsCount == 0) {
366+
indexEnd = index
367+
break
368+
}
369+
} else if (content[index] == "{") {
370+
nestedOpenBracketsCount++
368371
}
369-
}
370-
else if (content[index] == "{")
371-
{
372-
nestedOpenBracketsCount++;
373-
}
374372

375-
index++;
373+
index++
374+
}
376375
}
377376

378-
if (indexEnd != -1)
379-
{
377+
378+
if (indexEnd != -1) {
379+
// replace the productFlavor dimension with a shorter one - F0, F1, F2, etc.
380380
// full content of productFlavors { ... } -> the substring is parenthesis to parenthesis -> { ... }
381-
def oldProductFlavorsText = content.substring(indexStart, indexEnd + 1);
381+
def oldProductFlavorsText = content.substring(indexStart, indexEnd + 1)
382382

383383
def newProductFlavorsContent = updateProductFlavorsContent(flavor, dimension, oldProductFlavorsText);
384384

385-
return content.replace(oldProductFlavorsText, newProductFlavorsContent);
386-
}
387-
else
388-
{
385+
return content.replace(oldProductFlavorsText, newProductFlavorsContent)
386+
} else {
387+
// create a productFlavor dimension - F0, F1, F2, etc.
389388
def androidContentExists = content.indexOf("android {") != -1;
390389
def newProductFlavorsContent = createProductFlavorsContent(flavor, dimension, !androidContentExists);
391390

0 commit comments

Comments
 (0)