15
15
* -PsupportVersion=[support_version] (default (22.2.0)
16
16
* -PcompileSdk=[compile_sdk_version] (default 22)
17
17
*
18
- * -PrunSBGenerator //this flag will triger static binding generation
18
+ * -PdontRunSbg=[true/false] (default false)
19
19
*/
20
20
21
21
buildscript {
@@ -33,15 +33,19 @@ apply plugin: "com.android.application"
33
33
def isWinOs = System . properties[' os.name' ]. toLowerCase(). contains(' windows' )
34
34
def metadataParams = new LinkedList <String > ()
35
35
def allJarPaths = new LinkedList <String > ()
36
- def configurationsDir = " configurations"
36
+ def configurationsDir = " $p rojectDir / configurations"
37
37
def createPluginConfigFile = false
38
38
def configStage = " \n :config phase: "
39
39
def nodeModulesDir = " ../../node_modules/"
40
- def libDir = " ../../lib/Android/"
41
- def pluginNames = new ArrayList<String > ()
40
+ def libDir = " $p rojectDir / ../../lib/Android/"
41
+ def flavorNames = new ArrayList<String > ()
42
42
def configDir = file(configurationsDir)
43
- def appResExists = false
44
- def appResourcesName = " NativescriptAppResources"
43
+
44
+ def dontRunSbg = project. hasProperty(" dontRunSbg" );
45
+
46
+ def asbgProject = project(" :asbg" )
47
+ asbgProject. ext. outDir = new File (" $projectDir " , " src/main/java" )
48
+ asbgProject. ext. jsCodeDir = new File (" $projectDir " , " src/main/assets/app" )
45
49
46
50
def compiteCompileSdkVersion () {
47
51
if (project. hasProperty(" compileSdk" )) {
@@ -66,7 +70,7 @@ def computeBuildToolsVersion() {
66
70
return buildToolsVersion
67
71
}
68
72
else {
69
- return " 22 .0.1"
73
+ return " 23 .0.1"
70
74
}
71
75
}
72
76
project. ext. selectedBuildType = project. hasProperty(" release" ) ? " release" : " debug"
@@ -102,7 +106,7 @@ android {
102
106
}
103
107
104
108
sourceSets. main {
105
- jniLibs. srcDir " libs/jni"
109
+ jniLibs. srcDir " $p rojectDir / libs/jni"
106
110
}
107
111
108
112
signingConfigs {
@@ -136,7 +140,15 @@ android {
136
140
def variantName = variant. name. capitalize()
137
141
def compileSourcesTaskName = " compile${ variantName} Sources"
138
142
def compileSourcesTask = project. tasks. findByName(compileSourcesTaskName)
139
- compileSourcesTask. finalizedBy " buildMetadata"
143
+
144
+ def generateBuildConfigTask = variant. generateBuildConfig;
145
+ generateBuildConfigTask. finalizedBy(collectAllJars)
146
+
147
+ if (! dontRunSbg) {
148
+ collectAllJars. finalizedBy(setProperties)
149
+ }
150
+
151
+ compileSourcesTask. finalizedBy(buildMetadata)
140
152
}
141
153
}
142
154
@@ -158,7 +170,7 @@ dependencies {
158
170
compile " com.android.support:appcompat-v7:$suppotVer "
159
171
160
172
// take all jars within the libs dir
161
- compile fileTree(dir : " libs" , include : [" **/*.jar" ])
173
+ compile fileTree(dir : " $p rojectDir / libs" , include : [" **/*.jar" ])
162
174
163
175
// take all jars within the node_modules dir
164
176
compile fileTree(dir : nodeModulesDir, include : [" **/platforms/android/**/*.jar" ], exclude : ' **/.bin/**' )
@@ -194,9 +206,8 @@ task pluginStructureCheck {
194
206
}
195
207
}
196
208
197
-
198
209
def createIncludeFile (filePath , fileName , dimensionName ) {
199
- println " \t +creating include.gradle file for: " + filePath + " flavor: " + fileName
210
+ println " \t +creating include.gradle file for: " + filePath
200
211
def defaultIncludeFile = new File (filePath, " include.gradle" )
201
212
defaultIncludeFile. write " "
202
213
defaultIncludeFile << " android { \n "
@@ -258,10 +269,10 @@ task createDefaultIncludeFiles {
258
269
}
259
270
}
260
271
261
- pluginNames . add(' "' + dimensionName + ' "' )
272
+ flavorNames . add(' "' + dimensionName + ' "' )
262
273
263
274
if (! foundIncludeFile) {
264
- // createIncludeFile(fl.getAbsolutePath(), fileName, dimensionName)
275
+ // createIncludeFile(fl.getAbsolutePath() , fileName, dimensionName)
265
276
createIncludeFile(fl. getAbsolutePath() , flavor, dimensionName)
266
277
}
267
278
}
@@ -279,7 +290,7 @@ task createPluginsConfigFile {
279
290
280
291
if (createPluginConfigFile) {
281
292
println " \t +creating product flavors include.gradle file in $configurationsDir folder..."
282
- def flavors = pluginNames . join(" ," )
293
+ def flavors = flavorNames . join(" ," )
283
294
284
295
flavorsFile << " android { \n "
285
296
flavorsFile << " \t flavorDimensions " + flavors + " \n "
@@ -291,7 +302,7 @@ task createPluginsConfigFile {
291
302
task pluginExtend {
292
303
description " applies additional configuration"
293
304
294
- def pathToAppGradle = " ../../app/App_Resources/Android/app.gradle"
305
+ def pathToAppGradle = " $p rojectDir / ../../app/App_Resources/Android/app.gradle"
295
306
def appGradle = file(pathToAppGradle)
296
307
if (appGradle. exists()) {
297
308
apply from : pathToAppGradle
@@ -323,13 +334,13 @@ task pluginExtend {
323
334
task copyAarDependencies (type : Copy ) {
324
335
println " $configStage copyAarDependencies"
325
336
from fileTree(dir : nodeModulesDir, include : [" **/*.aar" ], exclude : ' **/.bin/**' ). files
326
- into " libs/aar"
337
+ into " $p rojectDir / libs/aar"
327
338
}
328
339
329
340
task addAarDependencies << {
330
341
println " $configStage addAarDependencies"
331
342
// manually traverse all the locally copied AAR files and add them to the project compilation dependencies list
332
- FileTree tree = fileTree(dir : " libs/aar" , include : [" **/*.aar" ])
343
+ FileTree tree = fileTree(dir : " $p rojectDir / libs/aar" , include : [" **/*.aar" ])
333
344
tree. each { File file ->
334
345
// remove the extension of the file (.aar)
335
346
def length = file. name. length() - 4
@@ -345,11 +356,11 @@ task addAarDependencies << {
345
356
// //////////////////////////////////////////////////////////////////////////////////
346
357
347
358
task cleanLocalAarFiles (type : Delete ) {
348
- delete fileTree(dir : " libs/aar" , include : [" *.aar" ])
359
+ delete fileTree(dir : " $p rojectDir / libs/aar" , include : [" *.aar" ])
349
360
}
350
361
351
362
task ensureMetadataOutDir {
352
- def outputDir = file(" $r ootDir /metadata/output/assets/metadata" )
363
+ def outputDir = file(" $p rojectDir /metadata/output/assets/metadata" )
353
364
outputDir. mkdirs()
354
365
}
355
366
@@ -374,12 +385,35 @@ task collectAllJars {
374
385
}
375
386
376
387
metadataParams. add(" metadata-generator.jar" )
377
- metadataParams. add(" ../metadata/output/assets/metadata" )
388
+ metadataParams. add(" $projectDir /metadata/output/assets/metadata" )
389
+ def jars = new LinkedList<File > ()
378
390
for (def i = 0 ; i < allJarPaths. size(); i++ ) {
379
391
metadataParams. add(allJarPaths. get(i));
392
+ def f = new File (allJarPaths. get(i))
393
+ if (f. getName(). endsWith(" .jar" )) {
394
+ jars. add(f)
395
+ }
380
396
}
397
+ asbgProject. ext. jarFiles = jars
398
+ }
399
+ }
400
+
401
+ task buildMetadata (type : JavaExec ) {
402
+ description " builds metadata with provided jar dependencies"
403
+
404
+ inputs. files(allJarPaths)
405
+ inputs. dir(" $buildDir /intermediates/classes" )
406
+
407
+ outputs. files(" metadata/output/assets/metadata/treeNodeStream.dat" , " metadata/output/assets/metadata/treeStringsStream.dat" , " metadata/output/assets/metadata/treeValueStream.dat" )
408
+
409
+ doFirst {
410
+ workingDir " build-tools"
411
+
412
+ main " -jar"
381
413
382
- def classesDir = " $rootDir /build/intermediates/classes"
414
+ // get compiled classes to pass to metadata generator
415
+ // these need to be called after the classes have compiled
416
+ def classesDir = " $buildDir /intermediates/classes"
383
417
384
418
def classesSubDirs = new File (classesDir). listFiles()
385
419
@@ -398,30 +432,14 @@ task collectAllJars {
398
432
if (classesDirBuildType. exists()) {
399
433
metadataParams. add(classesDirBuildType. getAbsolutePath())
400
434
}
401
- }
402
- }
403
-
404
-
405
- task buildMetadata (type : JavaExec ) {
406
- description " builds metadata with provided jar dependencies"
407
-
408
- inputs. files(allJarPaths)
409
- inputs. dir(" build/intermediates/classes" )
410
-
411
- outputs. files(" metadata/output/assets/metadata/treeNodeStream.dat" , " metadata/output/assets/metadata/treeStringsStream.dat" , " metadata/output/assets/metadata/treeValueStream.dat" )
412
-
413
- doFirst {
414
- workingDir " build-tools"
415
-
416
- main " -jar"
417
435
418
436
args metadataParams. toArray()
419
437
}
420
438
421
439
doLast {
422
440
copy {
423
- from " metadata/output/assets/metadata"
424
- into " src/main/assets/metadata"
441
+ from " $p rojectDir / metadata/output/assets/metadata"
442
+ into " $p rojectDir / src/main/assets/metadata"
425
443
}
426
444
427
445
def files = new File (" ${ buildDir} /intermediates/res" ). listFiles()
@@ -445,14 +463,14 @@ task buildMetadata (type: JavaExec) {
445
463
446
464
exec {
447
465
ignoreExitValue true
448
- workingDir " metadata/output"
466
+ workingDir " $p rojectDir / metadata/output"
449
467
commandLine removeCmdParams. toArray()
450
468
}
451
469
452
470
def addCmdParams = new ArrayList<String > ([aaptCommand, " add" , tmpAPKPath, " assets/metadata/treeNodeStream.dat" , " assets/metadata/treeStringsStream.dat" , " assets/metadata/treeValueStream.dat" ])
453
471
454
472
exec {
455
- workingDir " metadata/output"
473
+ workingDir " $p rojectDir / metadata/output"
456
474
commandLine addCmdParams. toArray()
457
475
}
458
476
}
@@ -474,14 +492,20 @@ task deleteExplodedAarFolder (type: Delete) {
474
492
// //////////////////////////////////////////////////////////////////////////////////
475
493
// //////////////////////////// OPTIONAL TASKS //////////////////////////////////////
476
494
// //////////////////////////////////////////////////////////////////////////////////
477
- task runBindingGenerator (dependsOn : " ing:jar" ) {
478
- rootProject. jarsDir = allJarPaths
479
- }
480
- runBindingGenerator. dependsOn(" bg:jar" )
481
-
482
- task rbg (dependsOn : " asbg:generatebindings" )
483
-
495
+ task setProperties {
496
+ project. ext. jarFiles = []
497
+ doLast {
498
+ def list = [];
499
+ allJarPaths. each({f ->
500
+ if (f. endsWith(" .jar" )) {
501
+ list. add(f);
502
+ }
503
+ })
504
+ project. jarFiles = list;
505
+ }
506
+ }
484
507
508
+ setProperties. finalizedBy(" asbg:generateBindings" )
485
509
486
510
// //////////////////////////////////////////////////////////////////////////////////
487
511
// //////////////////////////// EXECUTION ORDER /////////////////////////////////////
@@ -518,4 +542,3 @@ task buildapk {
518
542
519
543
dependsOn deleteExplodedAarFolder
520
544
}
521
-
0 commit comments