15
15
* -PsupportVersion=[support_version] (default (22.2.0)
16
16
* -PcompileSdk=[compile_sdk_version] (default 22)
17
17
*
18
- * -PdontRunSbg=[true/false] (default false)
18
+ * -PrunSBGenerator //this flag will triger static binding generation
19
19
*/
20
20
21
21
buildscript {
@@ -33,19 +33,15 @@ 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 = " $p rojectDir / configurations"
36
+ def configurationsDir = " configurations"
37
37
def createPluginConfigFile = false
38
38
def configStage = " \n :config phase: "
39
39
def nodeModulesDir = " ../../node_modules/"
40
- def libDir = " $p rojectDir / ../../lib/Android/"
40
+ def libDir = " ../../lib/Android/"
41
41
def pluginNames = new ArrayList<String > ()
42
42
def configDir = file(configurationsDir)
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" )
43
+ def appResExists = false
44
+ def appResourcesName = " NativescriptAppResources"
49
45
50
46
def compiteCompileSdkVersion () {
51
47
if (project. hasProperty(" compileSdk" )) {
@@ -70,7 +66,7 @@ def computeBuildToolsVersion() {
70
66
return buildToolsVersion
71
67
}
72
68
else {
73
- return " 23 .0.1"
69
+ return " 22 .0.1"
74
70
}
75
71
}
76
72
project. ext. selectedBuildType = project. hasProperty(" release" ) ? " release" : " debug"
@@ -106,7 +102,7 @@ android {
106
102
}
107
103
108
104
sourceSets. main {
109
- jniLibs. srcDir " $p rojectDir / libs/jni"
105
+ jniLibs. srcDir " libs/jni"
110
106
}
111
107
112
108
signingConfigs {
@@ -140,15 +136,7 @@ android {
140
136
def variantName = variant. name. capitalize()
141
137
def compileSourcesTaskName = " compile${ variantName} Sources"
142
138
def compileSourcesTask = project. tasks. findByName(compileSourcesTaskName)
143
-
144
- def generateBuildConfigTask = variant. generateBuildConfig;
145
- generateBuildConfigTask. finalizedBy(collectAllJars)
146
-
147
- if (! dontRunSbg) {
148
- collectAllJars. finalizedBy(setProperties)
149
- }
150
-
151
- compileSourcesTask. finalizedBy(buildMetadata)
139
+ compileSourcesTask. finalizedBy " buildMetadata"
152
140
}
153
141
}
154
142
@@ -170,7 +158,7 @@ dependencies {
170
158
compile " com.android.support:appcompat-v7:$suppotVer "
171
159
172
160
// take all jars within the libs dir
173
- compile fileTree(dir : " $p rojectDir / libs" , include : [" **/*.jar" ])
161
+ compile fileTree(dir : " libs" , include : [" **/*.jar" ])
174
162
175
163
// take all jars within the node_modules dir
176
164
compile fileTree(dir : nodeModulesDir, include : [" **/platforms/android/**/*.jar" ], exclude : ' **/.bin/**' )
@@ -206,8 +194,9 @@ task pluginStructureCheck {
206
194
}
207
195
}
208
196
197
+
209
198
def createIncludeFile (filePath , fileName , dimensionName ) {
210
- println " \t +creating include.gradle file for: " + filePath
199
+ println " \t +creating include.gradle file for: " + filePath + " flavor: " + fileName
211
200
def defaultIncludeFile = new File (filePath, " include.gradle" )
212
201
defaultIncludeFile. write " "
213
202
defaultIncludeFile << " android { \n "
@@ -224,18 +213,27 @@ def sanatizeDimensionName(str) {
224
213
}
225
214
226
215
// make sure the include.gradle file, produced by the user, has only allowed characters in dimension attribute and remove any invalid characters if necessary
227
- def updateIncludeGradleFile (subFile , dimensionName ) {
216
+ def updateIncludeGradleFile (subFile , dimensionName , flavor ) {
228
217
def igFile = new File (subFile. getAbsolutePath())
229
218
def newContent = igFile. text. replaceAll(/ dimension\s +["'](.+?)["']/ ) { fullMatch , fDimension ->
230
219
def newFg = sanatizeDimensionName(fDimension)
231
220
dimensionName = newFg
232
221
return " dimension \" $newFg \" "
233
222
}
234
- igFile. text = newContent
223
+
224
+ // println "Before patch: " + newContent
225
+
226
+ def finalContent = newContent. replace(dimensionName + " \" {" , flavor + " \" {" )
227
+
228
+ // println "Dimension: " + dimensionName + " final content: " + finalContent
229
+
230
+ igFile. text = finalContent
235
231
236
232
return dimensionName
237
233
}
238
234
235
+ def flavorNumber = 0
236
+
239
237
task createDefaultIncludeFiles {
240
238
description " creates default include.gradle files for added plugins IF NECESSARY"
241
239
println " $configStage createDefaultIncludeFiles"
@@ -249,19 +247,22 @@ task createDefaultIncludeFiles {
249
247
createPluginConfigFile = true
250
248
def foundIncludeFile = false
251
249
250
+ def flavor = " F" + flavorNumber++
251
+
252
252
println " \t +found plugins: " + fileName
253
253
fl. listFiles(). each { subFile ->
254
254
255
255
if (subFile. name == " include.gradle" ) {
256
256
foundIncludeFile = true
257
- dimensionName = updateIncludeGradleFile(subFile, dimensionName)
257
+ dimensionName = updateIncludeGradleFile(subFile, dimensionName, flavor )
258
258
}
259
259
}
260
260
261
261
pluginNames. add(' "' + dimensionName + ' "' )
262
262
263
263
if (! foundIncludeFile) {
264
- createIncludeFile(fl. getAbsolutePath() ,fileName, dimensionName)
264
+ // createIncludeFile(fl.getAbsolutePath(), fileName, dimensionName)
265
+ createIncludeFile(fl. getAbsolutePath() , flavor, dimensionName)
265
266
}
266
267
}
267
268
}
@@ -290,7 +291,7 @@ task createPluginsConfigFile {
290
291
task pluginExtend {
291
292
description " applies additional configuration"
292
293
293
- def pathToAppGradle = " $p rojectDir / ../../app/App_Resources/Android/app.gradle"
294
+ def pathToAppGradle = " ../../app/App_Resources/Android/app.gradle"
294
295
def appGradle = file(pathToAppGradle)
295
296
if (appGradle. exists()) {
296
297
apply from : pathToAppGradle
@@ -322,13 +323,13 @@ task pluginExtend {
322
323
task copyAarDependencies (type : Copy ) {
323
324
println " $configStage copyAarDependencies"
324
325
from fileTree(dir : nodeModulesDir, include : [" **/*.aar" ], exclude : ' **/.bin/**' ). files
325
- into " $p rojectDir / libs/aar"
326
+ into " libs/aar"
326
327
}
327
328
328
329
task addAarDependencies << {
329
330
println " $configStage addAarDependencies"
330
331
// manually traverse all the locally copied AAR files and add them to the project compilation dependencies list
331
- FileTree tree = fileTree(dir : " $p rojectDir / libs/aar" , include : [" **/*.aar" ])
332
+ FileTree tree = fileTree(dir : " libs/aar" , include : [" **/*.aar" ])
332
333
tree. each { File file ->
333
334
// remove the extension of the file (.aar)
334
335
def length = file. name. length() - 4
@@ -344,11 +345,11 @@ task addAarDependencies << {
344
345
// //////////////////////////////////////////////////////////////////////////////////
345
346
346
347
task cleanLocalAarFiles (type : Delete ) {
347
- delete fileTree(dir : " $p rojectDir / libs/aar" , include : [" *.aar" ])
348
+ delete fileTree(dir : " libs/aar" , include : [" *.aar" ])
348
349
}
349
350
350
351
task ensureMetadataOutDir {
351
- def outputDir = file(" $p rojectDir /metadata/output/assets/metadata" )
352
+ def outputDir = file(" $r ootDir /metadata/output/assets/metadata" )
352
353
outputDir. mkdirs()
353
354
}
354
355
@@ -373,35 +374,12 @@ task collectAllJars {
373
374
}
374
375
375
376
metadataParams. add(" metadata-generator.jar" )
376
- metadataParams. add(" $projectDir /metadata/output/assets/metadata" )
377
- def jars = new LinkedList<File > ()
377
+ metadataParams. add(" ../metadata/output/assets/metadata" )
378
378
for (def i = 0 ; i < allJarPaths. size(); i++ ) {
379
379
metadataParams. add(allJarPaths. get(i));
380
- def f = new File (allJarPaths. get(i))
381
- if (f. getName(). endsWith(" .jar" )) {
382
- jars. add(f)
383
- }
384
380
}
385
- asbgProject. ext. jarFiles = jars
386
- }
387
- }
388
381
389
- task buildMetadata (type : JavaExec ) {
390
- description " builds metadata with provided jar dependencies"
391
-
392
- inputs. files(allJarPaths)
393
- inputs. dir(" $buildDir /intermediates/classes" )
394
-
395
- outputs. files(" metadata/output/assets/metadata/treeNodeStream.dat" , " metadata/output/assets/metadata/treeStringsStream.dat" , " metadata/output/assets/metadata/treeValueStream.dat" )
396
-
397
- doFirst {
398
- workingDir " build-tools"
399
-
400
- main " -jar"
401
-
402
- // get compiled classes to pass to metadata generator
403
- // these need to be called after the classes have compiled
404
- def classesDir = " $buildDir /intermediates/classes"
382
+ def classesDir = " $rootDir /build/intermediates/classes"
405
383
406
384
def classesSubDirs = new File (classesDir). listFiles()
407
385
@@ -420,14 +398,30 @@ task buildMetadata (type: JavaExec) {
420
398
if (classesDirBuildType. exists()) {
421
399
metadataParams. add(classesDirBuildType. getAbsolutePath())
422
400
}
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"
423
417
424
418
args metadataParams. toArray()
425
419
}
426
420
427
421
doLast {
428
422
copy {
429
- from " $p rojectDir / metadata/output/assets/metadata"
430
- into " $p rojectDir / src/main/assets/metadata"
423
+ from " metadata/output/assets/metadata"
424
+ into " src/main/assets/metadata"
431
425
}
432
426
433
427
def files = new File (" ${ buildDir} /intermediates/res" ). listFiles()
@@ -451,14 +445,14 @@ task buildMetadata (type: JavaExec) {
451
445
452
446
exec {
453
447
ignoreExitValue true
454
- workingDir " $p rojectDir / metadata/output"
448
+ workingDir " metadata/output"
455
449
commandLine removeCmdParams. toArray()
456
450
}
457
451
458
452
def addCmdParams = new ArrayList<String > ([aaptCommand, " add" , tmpAPKPath, " assets/metadata/treeNodeStream.dat" , " assets/metadata/treeStringsStream.dat" , " assets/metadata/treeValueStream.dat" ])
459
453
460
454
exec {
461
- workingDir " $p rojectDir / metadata/output"
455
+ workingDir " metadata/output"
462
456
commandLine addCmdParams. toArray()
463
457
}
464
458
}
@@ -480,20 +474,14 @@ task deleteExplodedAarFolder (type: Delete) {
480
474
// //////////////////////////////////////////////////////////////////////////////////
481
475
// //////////////////////////// OPTIONAL TASKS //////////////////////////////////////
482
476
// //////////////////////////////////////////////////////////////////////////////////
483
- task setProperties {
484
- project. ext. jarFiles = []
485
- doLast {
486
- def list = [];
487
- allJarPaths. each({f ->
488
- if (f. endsWith(" .jar" )) {
489
- list. add(f);
490
- }
491
- })
492
- project. jarFiles = list;
493
- }
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
484
496
- setProperties. finalizedBy(" asbg:generateBindings" )
497
485
498
486
// //////////////////////////////////////////////////////////////////////////////////
499
487
// //////////////////////////// EXECUTION ORDER /////////////////////////////////////
0 commit comments