-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
813 lines (672 loc) · 22.5 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
/*
* Script builds apk in release or debug mode
* To run:
* gradle buildapk -Prelease (release mode)
* gradle buildapk (debug mode -> default)
* Options:
* -Prelease //this flag will run build in release mode
* -PksPath=[path_to_keystore_file]
* -PksPassword=[password_for_keystore_file]
* -Palias=[alias_to_use_from_keystore_file]
* -Ppassword=[password_for_alias]
*
* -PtargetSdk=[target_sdk]
* -PbuildToolsVersion=[build_tools_version]
* -PsupportVersion=[support_version]
* -PcompileSdk=[compile_sdk_version]
* -PdontRunSbg=[true/false]
*/
import groovy.json.JsonSlurper //used to parse package.json
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Pattern;
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.2.3"
}
}
apply plugin: "com.android.application"
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
def metadataParams = new LinkedList <String> ()
def allJarPaths = new LinkedList <String> ()
def configurationsDir = "$projectDir/configurations"
def shouldCreatePluginConfigFile = false
def configStage = "\n:config phase: "
def nodeModulesDir = "../../node_modules/"
def libDir = "$projectDir/../../lib/Android/"
def flavorNames = new ArrayList<String>()
def configDir = file(configurationsDir)
def packageJsonContents = [:]
def excludedDevDependencies = ['**/.bin/**']
def dontRunSbg = project.hasProperty("dontRunSbg");
def asbgProject = project(":asbg")
asbgProject.ext.outDir = new File("$projectDir", "src/main/java")
asbgProject.ext.jsCodeDir = new File("$projectDir", "src/main/assets/app")
def computeCompileSdkVersion () {
if(project.hasProperty("compileSdk")) {
return compileSdk
}
else {
return 23
}
}
def computeTargetSdkVersion() {
if(project.hasProperty("targetSdk")) {
return targetSdk
}
else {
return 23
}
}
def computeBuildToolsVersion() {
if(project.hasProperty("buildToolsVersion")) {
return buildToolsVersion
}
else {
return "25.0.2"
}
}
project.ext.selectedBuildType = project.hasProperty("release") ? "release" : "debug"
def renameResultApks (variant) {
def name
variant.outputs.each { output ->
def apkDirectory = output.packageApplication.outputFile.parentFile
def abiName = "";
if(output.getFilter(com.android.build.OutputFile.ABI)) {
abiName = "-" + output.getFilter(com.android.build.OutputFile.ABI);
}
def apkNamePrefix = rootProject.name + "-" + variant.buildType.name + abiName
name = apkNamePrefix + ".apk"
output.packageApplication.outputFile = new File(apkDirectory, name);
}
}
// gets the devDependencies declared in the package.json and excludes them from the build
task getDevDependencies {
doLast {
println "$configStage getDevDependencies"
String content = new File("$projectDir/../../package.json").getText("UTF-8")
def jsonSlurper = new JsonSlurper()
def packageJsonMap = jsonSlurper.parseText(content)
packageJsonContents = packageJsonMap.devDependencies;
packageJsonContents.each { entry ->
excludedDevDependencies.add(entry.key + '/platforms/android/**/*.jar')
}
}
}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// CONFIGURATIONS ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
android {
compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()
defaultConfig {
minSdkVersion 17
targetSdkVersion computeTargetSdkVersion()
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
sourceSets.main {
jniLibs.srcDir "$projectDir/libs/jni"
}
signingConfigs {
release {
if(project.hasProperty("release")) {
if(project.hasProperty("ksPath") &&
project.hasProperty("ksPassword") &&
project.hasProperty("alias") &&
project.hasProperty("password"))
{
storeFile file(ksPath)
storePassword ksPassword
keyAlias alias
keyPassword password
}
}
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
renameResultApks(variant)
}
applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
def compileSourcesTaskName = "compile${variantName}Sources"
def compileSourcesTask = project.tasks.findByName(compileSourcesTaskName)
def generateBuildConfigTask = variant.generateBuildConfig;
generateBuildConfigTask.finalizedBy(collectAllJars)
if(!dontRunSbg) {
collectAllJars.finalizedBy(setProperties)
}
compileSourcesTask.finalizedBy(buildMetadata)
// forces packaging of resources and assets AFTER producing metadata
// Reference: https://github.com/NativeScript/android-runtime/issues/785
// Ensure metadata has been built and copied in assets before packaging
variant.outputs.each { output ->
def abiName = "";
if (output.getFilter(com.android.build.OutputFile.ABI)) {
abiName = output.getFilter(com.android.build.OutputFile.ABI)
def packageTask = project.tasks.findByName("package${output.name}")
if (packageTask) {
packageTask.dependsOn(buildMetadata)
}
}
}
// Compile the Java sources AFTER the Java code-generation step is done
def compileTask = project.tasks.findByName("compile${variantName}JavaWithJavac")
if (compileTask) {
compileTask.dependsOn("asbg:generateBindings")
}
}
}
repositories {
jcenter()
// used for local *.AAR files
flatDir {
dirs 'libs/aar'
}
maven { url "https://jitpack.io" }
}
dependencies {
def supportVer = "22.2.0";
if(project.hasProperty("supportVersion")) {
supportVer = supportVersion
}
compile "com.android.support:support-v4:$supportVer"
compile "com.android.support:appcompat-v7:$supportVer"
implementation "com.android.support:multidex:1.0.2"
implementation "com.android.support:support-v4:$supportVer"
implementation "com.android.support:appcompat-v7:$supportVer"
debugImplementation "com.android.support:design:$supportVer"
implementation 'com.google.android.gms:play-services-auth:15.0.1'
debugCompile "com.android.support:design:$supportVer"
// take all jars within the libs dir
compile fileTree(dir: "$projectDir/libs", include: ["**/*.jar"])
// take all jars within the node_modules dir
compile fileTree(dir: nodeModulesDir, include: ["**/platforms/android/**/*.jar"], exclude: excludedDevDependencies)
//when gradle has aar support this will be preferred instead of addAarDependencies
// compile files("$rootDir/libs/aar") {
// builtBy 'copyAarDependencies'
// }
copyNativeScriptAar()
compile project(':runtime')
}
def copyNativeScriptAar() {
def useV8SymbolsFlag = new File("$projectDir/build-tools/useV8");
def runtimeAarType = "optimized";
if (useV8SymbolsFlag.exists() && !useV8SymbolsFlag.isDirectory()) {
println "Using less-optimized runtime bundle.";
runtimeAarType = "regular";
}
copy {
from "$projectDir/libs/runtime-libs/nativescript-${runtimeAarType}.aar"
into "$projectDir/libs/runtime-libs/"
rename "nativescript-${runtimeAarType}.aar", "nativescript.aar"
}
}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// CONFIGURATION PHASE //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
def updateProductFlavorsContent(flavor, dimensionName, oldContent) {
def endIndex = oldContent.length() - 1;
def index = 0;
def newContent = "";
def level = -1;
def dimensionFound = false;
while(index <= endIndex) {
if(level == 0 && (oldContent[index] == '"' || oldContent[index] == "'")) {
def closingQuotes = oldContent.indexOf('"', index + 1);
if(closingQuotes == -1) {
closingQuotes = oldContent.indexOf("'", index + 1);
}
index = closingQuotes + 1;
newContent += "\"${flavor}\"";
continue;
}
if(oldContent[index] == "{") {
level++;
}
if(oldContent[index] == "}") {
level--;
}
if(level > 0) {
if(!dimensionFound && oldContent.indexOf("dimension", index) == index) {
newContent += "dimension \"${dimensionName}\"";
dimensionFound = true;
index += "dimension ".length();
def openingQuoutes = oldContent.indexOf('"', index);
if(openingQuoutes == -1) {
openingQuoutes = oldContent.indexOf("'", index);
}
def closingQuotes = oldContent.indexOf('"', openingQuoutes + 1);
if(closingQuotes == -1) {
closingQuotes = oldContent.indexOf("'", openingQuoutes + 1);
}
index = closingQuotes + 1;
}
}
newContent += oldContent[index];
index++;
}
return newContent;
}
def createProductFlavorsContent(flavor, dimensionName, includeAndroidContent = true) {
if (includeAndroidContent)
{
def content = """
android {
productFlavors {
"${flavor}" {
dimension "${dimensionName}"
}
}
}
"""
return content;
}
else
{
def content = """
productFlavors {
"${flavor}" {
dimension "${dimensionName}"
}
}
"""
return content;
}
}
def createIncludeFile (filePath, flavor, dimensionName) {
println "\t + creating include.gradle file for ${filePath}"
def defaultIncludeFile = new File(filePath, "include.gradle")
defaultIncludeFile.text = createProductFlavorsContent(flavor, dimensionName);
}
def sanitizeDimensionName(str) {
return str.replaceAll(/\W/, "")
}
def replaceProductFlavorInContent(content, dimension, flavor) {
def indexStart = content.indexOf("productFlavors");
def index = indexStart + "productFlavors".length();
def indexEnd = -1;
def nestedOpenBraketsCount = 0;
while (index < content.length())
{
// print content[index];
if (content[index] == "}")
{
nestedOpenBraketsCount--;
if (nestedOpenBraketsCount == 0)
{
indexEnd = index;
break;
}
}
else if (content[index] == "{")
{
nestedOpenBraketsCount++;
}
index++;
}
if (indexEnd != -1)
{
// full content of productFlavors { ... } -> the substring is parenthesis to parenthesis -> { ... }
def oldProductFlavorsText = content.substring(indexStart, indexEnd + 1);
def newProductFlavorsContent = updateProductFlavorsContent(flavor, dimension, oldProductFlavorsText);
return content.replace(oldProductFlavorsText, newProductFlavorsContent);
}
else
{
def androidContentExists = content.indexOf("android {") != -1;
def newProductFlavorsContent = createProductFlavorsContent(flavor, dimension, !androidContentExists);
if (androidContentExists)
{
return content.replace("android {", "android { ${newProductFlavorsContent}");
}
else
{
return "${newProductFlavorsContent} \t ${content}"
}
}
}
// make sure the include.gradle file provided by the user has only allowed characters in dimension attribute and remove any invalid characters if necessary
def updateIncludeGradleFile(targetFile, dimensionName, flavor) {
def fileEntry = new File(targetFile.getAbsolutePath());
def content = fileEntry.text;
def replacedContent = replaceProductFlavorInContent(content, dimensionName, flavor);
fileEntry.text = replacedContent;
}
def renamePluginDirToFlavorName(directory, flavor) {
def parentName = directory.getName();
def parentFile = new File("src", parentName);
if (parentFile.exists())
{
def targetDirName = new File("src", flavor);
println "Renaming plugin directory to flavor name: ${parentFile.getAbsolutePath()} -> ${targetDirName.getAbsolutePath()}";
parentFile.renameTo(targetDirName);
}
}
def flavorNumber = 0
task createDefaultIncludeFiles {
description "creates default include.gradle files for added plugins IF NECESSARY"
println "$configStage createDefaultIncludeFiles"
def ft = file(configurationsDir)
ft.listFiles().each { file ->
if (file.isDirectory()) {
shouldCreatePluginConfigFile = true
def hasChildrenDirs = false
file.listFiles().each { subFile ->
if (subFile.isDirectory()) {
hasChildrenDirs = true
}
}
// if plugin is scoped - traverse its children directories
// e.g. @scope/plugin-with-android-aars
if (hasChildrenDirs) {
file.listFiles().each { subFile ->
if (subFile.isDirectory()) {
createIncludeGradleForPlugin(subFile, flavorNumber++, flavorNames)
}
}
} else {
createIncludeGradleForPlugin(file, flavorNumber++, flavorNames)
}
}
}
}
def createIncludeGradleForPlugin(file, flavorNumber, flavorNames) {
def parentDir = new File(file.getParent())
def parentName = parentDir.name
def dirToRename = file
if (parentName.indexOf("@") == 0) {
dirToRename = new File(parentName + "_" + file.name)
}
def foundIncludeFile = false
def fileName = file.name
def dimensionName = sanitizeDimensionName(fileName)
def flavor = "F" + flavorNumber
println "\t+found plugins: " + fileName
file.listFiles().each { subFile ->
if (subFile.name == "include.gradle") {
foundIncludeFile = true
updateIncludeGradleFile(subFile, dimensionName, flavor)
renamePluginDirToFlavorName(dirToRename, flavor);
}
}
flavorNames.add('"' + dimensionName + '"')
if (!foundIncludeFile) {
createIncludeFile(file.getAbsolutePath() , flavor, dimensionName)
renamePluginDirToFlavorName(dirToRename, flavor);
}
}
task createPluginsConfigFile {
description "creates product flavor config file based on what plugins are added"
if (configDir.exists()) {
println "$configStage createPluginsConfigFile"
def flavorsFile = new File("$configurationsDir/include.gradle")
if(shouldCreatePluginConfigFile) {
println "\t Creating product flavors include.gradle file in $configurationsDir folder..."
def flavors = flavorNames.join(", ")
def content = """
android {
flavorDimensions ${flavors}
}
"""
flavorsFile.text = content
}
}
}
task pluginExtend {
description "applies additional configuration"
def pathToAppGradle = "$projectDir/../../app/App_Resources/Android/app.gradle"
def appGradle = file(pathToAppGradle)
if(appGradle.exists()) {
apply from: pathToAppGradle
}
if(configDir.exists()) {
println "$configStage pluginExtend"
configDir.eachFileRecurse(groovy.io.FileType.FILES) {
if(it.name.equals('include.gradle')) {
println "\t+applying configuration from: " + it
apply from: it
}
}
}
}
//// doesn't work unless task is explicitly called (TODO: research configurations hook)
// addAarDependencies.dependsOn(copyAarDependencies)
// createDefaultIncludeFiles.dependsOn(addAarDependencies)
// createPluginsConfigFile.dependsOn(createDefaultIncludeFiles)
// pluginExtend.dependsOn(createPluginsConfigFile)
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// BEFORE EXECUTION /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// we need to copy all dependencies into a flat dir, as pointed by the repositories configurations at the top
task copyAarDependencies (type: Copy) {
def filterAarFilesFn = { path, attrs ->
String pathString = path.toString();
def isBin = Pattern.matches(".*/\\.bin/.*", pathString);
def isAar = Pattern.matches(".*\\.aar\$", pathString);
return !isBin && isAar;
}
def mapToStringFn = { path ->
return path.toString();
}
Object[] files = Files.find(
Paths.get("$projectDir", "$nodeModulesDir"),
Integer.MAX_VALUE,
filterAarFilesFn,
java.nio.file.FileVisitOption.FOLLOW_LINKS
)
.map(mapToStringFn)
.toArray();
into "$projectDir/libs/aar"
from files
}
task addAarDependencies {
doLast {
println "$configStage addAarDependencies"
// manually traverse all the locally copied AAR files and add them to the project compilation dependencies list
FileTree tree = fileTree(dir: "$projectDir/libs/aar", include: ["**/*.aar"])
tree.each { File file ->
// remove the extension of the file (.aar)
def length = file.name.length() - 4
def fileName = file.name[0..<length]
println "\t+adding dependency: " + file.getAbsolutePath()
project.dependencies.add("compile", [name: fileName, ext: "aar"])
}
}
}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// EXECUTUION PHASE /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
task cleanLocalAarFiles(type: Delete) {
delete fileTree(dir: "$projectDir/libs/aar", include: ["*.aar"])
}
task ensureMetadataOutDir {
def outputDir = file("$projectDir/metadata/output/assets/metadata")
outputDir.mkdirs()
}
task collectAllJars {
description "gathers all paths to jar dependencies before building metadata with them"
def explodedAarDir = project.buildDir.getAbsolutePath() + "/intermediates/exploded-aar/"
def sdkPath = android.sdkDirectory.getAbsolutePath();
def androidJar = sdkPath + "/platforms/" + android.compileSdkVersion + "/android.jar"
doFirst {
configurations.compile.each { File dependencyFile ->
// println "\t+" + dependencyFile.getAbsolutePath()
allJarPaths.add(dependencyFile.getAbsolutePath())
}
allJarPaths.add(androidJar);
def ft = fileTree(dir: explodedAarDir, include: "**/*.jar")
ft.each { currentJarFile ->
allJarPaths.add(currentJarFile.getAbsolutePath())
}
metadataParams.add("metadata-generator.jar");
metadataParams.add("$projectDir/metadata/output/assets/metadata");
def jars = new LinkedList<File>()
for(def i = 0; i < allJarPaths.size(); i++) {
metadataParams.add(allJarPaths.get(i));
def f = new File(allJarPaths.get(i))
if (f.getName().endsWith(".jar")) {
jars.add(f)
}
}
asbgProject.ext.jarFiles = jars
}
}
task buildMetadata (type: JavaExec) {
description "builds metadata with provided jar dependencies"
inputs.files(allJarPaths)
inputs.dir("$buildDir/intermediates/classes")
outputs.files("metadata/output/assets/metadata/treeNodeStream.dat", "metadata/output/assets/metadata/treeStringsStream.dat", "metadata/output/assets/metadata/treeValueStream.dat")
doFirst {
// get compiled classes to pass to metadata generator
// these need to be called after the classes have compiled
def classesDir = "$buildDir/intermediates/classes"
def classesSubDirs = new File(classesDir).listFiles()
def selectedBuildType = project.ext.selectedBuildType
for (File subDir: classesSubDirs) {
if (!subDir.getName().equals(selectedBuildType)) {
def subDirBuildType = new File(subDir, selectedBuildType)
if (subDirBuildType.exists()) {
metadataParams.add(subDirBuildType.getAbsolutePath());
}
}
}
def classesDirBuildType = new File(classesDir, selectedBuildType)
if (classesDirBuildType.exists()) {
metadataParams.add(classesDirBuildType.getAbsolutePath())
}
workingDir "build-tools"
main "-jar"
args metadataParams.toArray()
}
doLast {
copy {
from "$projectDir/metadata/output/assets/metadata"
into "$projectDir/src/main/assets/metadata"
}
}
}
task generateTypescriptDefinitions (type: JavaExec) {
def paramz = new ArrayList<String>();
def includeDirs = ["com.android.support", "/platforms/" + android.compileSdkVersion]
doFirst {
delete "build-tools/typings"
workingDir "build-tools"
main "-jar"
paramz.add("dts-generator.jar");
paramz.add("-input");
for (String jarPath: project.jarFiles) {
// don't generate typings for runtime jars and classes
if (shouldIncludeDirForTypings(jarPath, includeDirs)) {
paramz.add(jarPath);
}
}
paramz.add("-output");
paramz.add("typings");
args paramz.toArray();
}
}
generateTypescriptDefinitions.onlyIf {
project.hasProperty("generateTypings") && Boolean.parseBoolean(project.generateTypings)
}
def shouldIncludeDirForTypings(path, includeDirs) {
for (String p: includeDirs) {
if (path.indexOf(p) > -1) {
return true;
}
}
return false;
}
task copyTypings {
doLast {
println "Copied generated typings to application root level. Make sure to import android.d.ts in reference.d.ts"
copy {
from "$projectDir/build-tools/typings"
into "$projectDir/../../"
}
}
}
copyTypings.onlyIf({
generateTypescriptDefinitions.didWork;
})
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////// OPTIONAL TASKS //////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
task setProperties {
project.ext.jarFiles = []
doLast {
def list = [];
allJarPaths.each({f ->
if(f.endsWith(".jar")) {
list.add(f);
}
})
project.jarFiles = list;
}
}
setProperties.finalizedBy("asbg:generateBindings", generateTypescriptDefinitions)
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////// EXECUTION ORDER /////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
// -- configuration phase
// 1. Copy *.aar dependencies
// 2. Add *.aar dependencies
// 3. create default include files
// 4. create plugins config file
// 5. plugin extend (apply from include files)
// --execution phase
ensureMetadataOutDir.dependsOn(cleanLocalAarFiles)
collectAllJars.dependsOn(ensureMetadataOutDir)
buildMetadata.dependsOn(collectAllJars)
generateTypescriptDefinitions.finalizedBy(copyTypings)
//DO NOT UNCOMMENT
// mergeAssets.dependsOn(copyMetadata) -> look in CONFIGURATIONS(top) in android.applicationVariants to see how it's done
task buildapk {
// problem is compile dependencies need to be changed before configuration stage
// and this is the only way so far
tasks.copyAarDependencies.execute()
tasks.addAarDependencies.execute()
//done to build only necessary apk
if(project.hasProperty("release")) {
dependsOn "assembleRelease"
}
else {
dependsOn "assembleDebug"
}
}
//////// custom clean ///////////
task deleteMetadata (type: Delete){
delete "$projectDir/metadata/output"
}
task deleteFlavors (type: Delete){
doLast {
def srcDir = new File("$projectDir/src")
srcDir.listFiles().each({ f ->
if(!f.getName().equals("main") &&
!f.getName().equals("debug") &&
!f.getName().equals("release")) {
delete f
}
})
}
}
task deleteConfigurations (type: Delete) {
delete "$projectDir/configurations"
}
task deleteGeneratedBindings(type: Delete) {
delete "$projectDir/src/main/java/com/tns/gen"
}
deleteMetadata.dependsOn(":asbg:clean")
deleteFlavors.dependsOn(deleteMetadata)
deleteConfigurations.dependsOn(deleteFlavors)
deleteGeneratedBindings.dependsOn(deleteConfigurations)
clean.dependsOn(deleteGeneratedBindings)