@@ -40,7 +40,7 @@ def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
40
40
def metadataParams = new LinkedList <String > ()
41
41
def allJarPaths = new LinkedList <String > ()
42
42
def configurationsDir = " $projectDir /configurations"
43
- def createPluginConfigFile = false
43
+ def shouldCreatePluginConfigFile = false
44
44
def configStage = " \n :config phase: "
45
45
def nodeModulesDir = " ../../node_modules/"
46
46
def libDir = " $projectDir /../../lib/Android/"
@@ -55,7 +55,7 @@ def asbgProject = project(":asbg")
55
55
asbgProject. ext. outDir = new File (" $projectDir " , " src/main/java" )
56
56
asbgProject. ext. jsCodeDir = new File (" $projectDir " , " src/main/assets/app" )
57
57
58
- def compiteCompileSdkVersion () {
58
+ def computeCompileSdkVersion () {
59
59
if (project. hasProperty(" compileSdk" )) {
60
60
return compileSdk
61
61
}
@@ -118,14 +118,14 @@ task getDevDependencies {
118
118
// //////////////////////////////////////////////////////////////////////////////////
119
119
120
120
android {
121
- compileSdkVersion compiteCompileSdkVersion ()
121
+ compileSdkVersion computeCompileSdkVersion ()
122
122
buildToolsVersion computeBuildToolsVersion()
123
123
124
124
defaultConfig {
125
125
minSdkVersion 17
126
126
targetSdkVersion computeTargetSdkVersion()
127
127
ndk {
128
- abiFilters " armeabi-v7a" , " x86"
128
+ abiFilters " armeabi-v7a" , " x86"
129
129
}
130
130
}
131
131
@@ -183,14 +183,14 @@ repositories {
183
183
}
184
184
185
185
dependencies {
186
- def suppotVer = " 22.2.0" ;
186
+ def supportVer = " 22.2.0" ;
187
187
if (project. hasProperty(" supportVersion" )) {
188
- suppotVer = supportVersion
188
+ supportVer = supportVersion
189
189
}
190
190
191
- compile " com.android.support:support-v4:$s uppotVer "
192
- compile " com.android.support:appcompat-v7:$s uppotVer "
193
- debugCompile " com.android.support:design:$s uppotVer "
191
+ compile " com.android.support:support-v4:$s upportVer "
192
+ compile " com.android.support:appcompat-v7:$s upportVer "
193
+ debugCompile " com.android.support:design:$s upportVer "
194
194
195
195
// take all jars within the libs dir
196
196
compile fileTree(dir : " $projectDir /libs" , include : [" **/*.jar" ])
@@ -268,7 +268,7 @@ def updateProductFlavorsContent(flavor, dimensionName, oldContent) {
268
268
def closingQuotes = oldContent. indexOf(' "' , openingQuoutes + 1 );
269
269
if (closingQuotes == -1 ) {
270
270
closingQuotes = oldContent. indexOf(" '" , openingQuoutes + 1 );
271
- }
271
+ }
272
272
273
273
index = closingQuotes + 1 ;
274
274
}
@@ -282,8 +282,7 @@ def updateProductFlavorsContent(flavor, dimensionName, oldContent) {
282
282
return newContent;
283
283
}
284
284
285
- def createProductFlavorsContent (flavor , dimensionName , includeAndroidContent = true )
286
- {
285
+ def createProductFlavorsContent (flavor , dimensionName , includeAndroidContent = true ) {
287
286
if (includeAndroidContent)
288
287
{
289
288
def content = """
@@ -317,12 +316,11 @@ def createIncludeFile (filePath, flavor, dimensionName) {
317
316
defaultIncludeFile. text = createProductFlavorsContent(flavor, dimensionName);
318
317
}
319
318
320
- def sanatizeDimensionName (str ) {
319
+ def sanitizeDimensionName (str ) {
321
320
return str. replaceAll(/ \W / , " " )
322
321
}
323
322
324
- def replaceProductFlavorInContent (content , dimension , flavor )
325
- {
323
+ def replaceProductFlavorInContent (content , dimension , flavor ) {
326
324
def indexStart = content. indexOf(" productFlavors" );
327
325
def index = indexStart + " productFlavors" . length();
328
326
def indexEnd = -1 ;
@@ -373,17 +371,16 @@ def replaceProductFlavorInContent(content, dimension, flavor)
373
371
}
374
372
}
375
373
}
376
- // make sure the include.gradle file, produced by the user, has only allowed characters in dimension attribute and remove any invalid characters if necessary
377
- def updateIncludeGradleFile ( targetFile , dimensionName , flavor )
378
- {
374
+
375
+ // make sure the include.gradle file provided by the user has only allowed characters in dimension attribute and remove any invalid characters if necessary
376
+ def updateIncludeGradleFile ( targetFile , dimensionName , flavor ) {
379
377
def fileEntry = new File (targetFile. getAbsolutePath());
380
378
def content = fileEntry. text;
381
379
def replacedContent = replaceProductFlavorInContent(content, dimensionName, flavor);
382
380
fileEntry. text = replacedContent;
383
381
}
384
382
385
- def renamePluginDirToFlavorName (directory , flavor )
386
- {
383
+ def renamePluginDirToFlavorName (directory , flavor ) {
387
384
def parentName = directory. getName();
388
385
def parentFile = new File (" src" , parentName);
389
386
if (parentFile. exists())
@@ -401,44 +398,73 @@ task createDefaultIncludeFiles {
401
398
println " $configStage createDefaultIncludeFiles"
402
399
def ft = file(configurationsDir)
403
400
404
- ft. listFiles(). each { fl ->
405
-
406
- if (fl. isDirectory()) {
407
- def fileName = fl. name
408
- def dimensionName = sanatizeDimensionName(fileName)
409
- createPluginConfigFile = true
410
- def foundIncludeFile = false
411
-
412
- def flavor = " F" + flavorNumber++
413
- println " \t +found plugins: " + fileName
414
- fl. listFiles(). each { subFile ->
415
-
416
- if (subFile. name == " include.gradle" ) {
417
- foundIncludeFile = true
418
- updateIncludeGradleFile(subFile, dimensionName, flavor)
419
- renamePluginDirToFlavorName(subFile. getParentFile(), flavor);
401
+ ft. listFiles(). each { file ->
402
+ if (file. isDirectory()) {
403
+ shouldCreatePluginConfigFile = true
404
+ def hasChildrenDirs = false
405
+ file. listFiles(). each { subFile ->
406
+ if (subFile. isDirectory()) {
407
+ hasChildrenDirs = true
420
408
}
421
409
}
422
-
423
- flavorNames. add(' "' + dimensionName + ' "' )
424
-
425
- if (! foundIncludeFile) {
426
- createIncludeFile(fl. getAbsolutePath() , flavor, dimensionName)
427
- renamePluginDirToFlavorName(fl, flavor);
428
- }
410
+
411
+ // if plugin is scoped - traverse its children directories
412
+ // e.g. @scope/plugin-with-android-aars
413
+ if (hasChildrenDirs) {
414
+ file. listFiles(). each { subFile ->
415
+ if (subFile. isDirectory()) {
416
+ flavorNumber++
417
+ createIncludeGradleForPlugin(subFile, flavorNumber, flavorNames)
418
+ }
419
+ }
420
+ } else {
421
+ flavorNumber++
422
+ createIncludeGradleForPlugin(file, flavorNumber, flavorNames)
423
+ }
429
424
}
430
425
}
431
426
}
432
427
428
+ def createIncludeGradleForPlugin (file , flavorNumber , flavorNames ) {
429
+ def parentDir = new File (file. getParent())
430
+ def parentName = parentDir. name
431
+ def dirToRename = file
432
+
433
+ if (parentName. indexOf(" @" ) == 0 ) {
434
+ dirToRename = new File (parentName + " _" + file. name)
435
+ }
436
+
437
+ def foundIncludeFile = false
438
+ def fileName = file. name
439
+ def dimensionName = sanitizeDimensionName(fileName)
440
+
441
+ def flavor = " F" + flavorNumber
442
+ println " \t +found plugins: " + fileName
443
+ file. listFiles(). each { subFile ->
444
+ if (subFile. name == " include.gradle" ) {
445
+ foundIncludeFile = true
446
+ updateIncludeGradleFile(subFile, dimensionName, flavor)
447
+ renamePluginDirToFlavorName(dirToRename, flavor);
448
+ }
449
+ }
450
+
451
+ flavorNames. add(' "' + dimensionName + ' "' )
452
+
453
+ if (! foundIncludeFile) {
454
+ createIncludeFile(file. getAbsolutePath() , flavor, dimensionName)
455
+ renamePluginDirToFlavorName(dirToRename, flavor);
456
+ }
457
+ }
458
+
433
459
task createPluginsConfigFile {
434
460
description " creates product flavor config file based on what plugins are added"
435
461
436
- if (configDir. exists()) {
462
+ if (configDir. exists()) {
437
463
println " $configStage createPluginsConfigFile"
438
464
439
465
def flavorsFile = new File (" $configurationsDir /include.gradle" )
440
466
441
- if (createPluginConfigFile ) {
467
+ if (shouldCreatePluginConfigFile ) {
442
468
println " \t Creating product flavors include.gradle file in $configurationsDir folder..."
443
469
def flavors = flavorNames. join(" , " )
444
470
0 commit comments