@@ -39,22 +39,20 @@ def metadataParams = new LinkedList <String> ()
39
39
def allJarPaths = new LinkedList <String > ()
40
40
def configStage = " \t config phase: "
41
41
def nodeModulesDir = " ../../node_modules/"
42
- def configurationsDir = new File (projectDir, " build/configurations" )
43
42
def dependenciesJson = file(" dependencies.json" )
44
43
45
44
// the build script will not work with previous versions of the CLI (3.1 or earlier)
46
45
if (! dependenciesJson. exists()) {
47
46
throw new BuildCancelledException ("""
48
47
'dependencies.json' file not found. Check whether the NativeScript CLI has prepared the project beforehand,
49
- and that your NativeScript version is 3.2 , or a more recent one. To build an android project with the current
50
- version of the {N} CLI install a previous version of the runtime package - 'tns platform add android@3.1 '.
48
+ and that your NativeScript version is 3.3 , or a more recent one. To build an android project with the current
49
+ version of the {N} CLI install a previous version of the runtime package - 'tns platform add android@3.2 '.
51
50
""" )
52
51
}
53
52
54
53
def nativescriptDependencies = new JsonSlurper (). parseText(dependenciesJson. text)
55
54
56
55
def packageJsonContents = [:]
57
- def excludedDevDependencies = [' **/.bin/**' ]
58
56
59
57
def dontRunSbg = project. hasProperty(" dontRunSbg" );
60
58
def asbgProject = project(" :asbg" )
@@ -81,25 +79,74 @@ def renameResultApks = { variant ->
81
79
}
82
80
}
83
81
84
- // gets the devDependencies declared in the package.json and excludes them from the build
85
- task getDevDependencies {
86
- doLast {
87
- println " $configStage getDevDependencies"
82
+ // //////////////////////////////////////////////////////////////////////////////////
83
+ // /////////////////////////// CONFIGURATIONS ///////////////////////////////////////
84
+ // //////////////////////////////////////////////////////////////////////////////////
85
+
86
+ def applyPluginsIncludeGradleConfigurations = { ->
87
+ def taskNames = project. getGradle(). startParameter. taskNames
88
+
89
+ // don't apply plugin configurations if clean is invoked
90
+ if (taskNames && taskNames. size() > 0 && taskNames. getAt(0 ). equals(" clean" )) {
91
+ return []
92
+ }
93
+
94
+ def configurationsDir = new File (projectDir, " build/configurations" )
95
+ configurationsDir. deleteDir()
96
+
97
+ def dimensions = []
98
+ def includes = new ArrayList<String > ()
99
+ def flavorNumber = 0
100
+
101
+ nativescriptDependencies. each { dep ->
102
+ def androidDir = file(" ${ dep.directory} /platforms/android" )
103
+ if (! androidDir. exists()) {
104
+ return
105
+ }
106
+
107
+ def packageJsonPath = file(" ${ dep.directory} /package.json" )
108
+ def packageJson = new JsonSlurper (). parseText(packageJsonPath. text)
109
+ def pluginName = packageJson. name
110
+ def dimensionName = sanitizeDimensionName(pluginName)
88
111
89
- String content = new File (" $projectDir /../../package.json" ). getText(" UTF-8" )
90
- def jsonSlurper = new JsonSlurper ()
91
- def packageJsonMap = jsonSlurper. parseText(content)
112
+ dimensions. add(dimensionName)
113
+ def flavor = " F${ flavorNumber++} "
114
+
115
+ def includeGradleFile = new File (androidDir, " include.gradle" )
116
+ def destinationDir = file(" ${ configurationsDir} /${ pluginName} /" )
117
+ def destinationIncludeGradleFile = file(" ${ configurationsDir} /${ pluginName} /include.gradle" )
92
118
93
- packageJsonContents = packageJsonMap . devDependencies;
119
+ Files . createDirectories( Paths . get(destinationDir . getAbsolutePath()))
94
120
95
- packageJsonContents. each { entry ->
96
- excludedDevDependencies. add(entry. key + ' /platforms/android/**/*.jar' )
121
+ if (includeGradleFile. exists()) {
122
+ println " \t + add include.gradle from ${ includeGradleFile} "
123
+ destinationIncludeGradleFile. text = modifyProductFlavorInContent(includeGradleFile. text, dimensionName, flavor)
124
+ } else {
125
+ println " \t + creating include.gradle for plugin ${ file(dep.directory)} "
126
+ destinationIncludeGradleFile. text = createProductFlavorsContent(flavor, dimensionName)
97
127
}
128
+
129
+ includes. add(destinationIncludeGradleFile. getAbsolutePath());
130
+
131
+ copyAndRenamePluginDirToFlavorName(androidDir, flavor);
132
+ }
133
+
134
+ includes. each {
135
+ println " \t + applying plugin configuration from ${ it} "
136
+ apply from : it
137
+ }
138
+
139
+ return dimensions
140
+ }
141
+
142
+ def applyAppGradleConfiguration = { ->
143
+ def pathToAppGradle = " $projectDir /../../app/App_Resources/Android/app.gradle"
144
+ def appGradle = file(pathToAppGradle)
145
+ if (appGradle. exists()) {
146
+ println " \t + applying user-defined configuration from ${ appGradle} "
147
+ apply from : pathToAppGradle
98
148
}
99
149
}
100
- // //////////////////////////////////////////////////////////////////////////////////
101
- // /////////////////////////// CONFIGURATIONS ///////////////////////////////////////
102
- // //////////////////////////////////////////////////////////////////////////////////
103
150
104
151
android {
105
152
compileSdkVersion computeCompileSdkVersion()
@@ -177,6 +224,12 @@ android {
177
224
compileTask. dependsOn(" asbg:generateBindings" )
178
225
}
179
226
}
227
+
228
+ def dimensions = applyPluginsIncludeGradleConfigurations()
229
+
230
+ flavorDimensions(* dimensions)
231
+
232
+ applyAppGradleConfiguration()
180
233
}
181
234
182
235
repositories {
@@ -204,9 +257,6 @@ dependencies {
204
257
205
258
// take all jars within the libs dir
206
259
compile fileTree(dir : " $projectDir /libs" , include : [" **/*.jar" ])
207
-
208
- // take all jars within the node_modules dir
209
- compile fileTree(dir : nodeModulesDir, include : [" **/platforms/android/**/*.jar" ], exclude : excludedDevDependencies)
210
260
}
211
261
212
262
// //////////////////////////////////////////////////////////////////////////////////
@@ -245,67 +295,6 @@ task addDependenciesFromNativeScriptPlugins {
245
295
}
246
296
}
247
297
248
- task applyPluginsIncludeGradleConfigurations {
249
- configurationsDir. deleteDir()
250
-
251
- def dimensions = []
252
- def includes = new ArrayList<String > ()
253
- def flavorNumber = 0
254
-
255
- nativescriptDependencies. each { dep ->
256
- def androidDir = file(" ${ dep.directory} /platforms/android" )
257
- if (! androidDir. exists()) {
258
- return
259
- }
260
-
261
- def packageJsonPath = file(" ${ dep.directory} /package.json" )
262
- def packageJson = new JsonSlurper (). parseText(packageJsonPath. text)
263
- def pluginName = packageJson. name
264
- def dimensionName = sanitizeDimensionName(pluginName)
265
-
266
- dimensions. add(dimensionName)
267
- def flavor = " F${ flavorNumber++} "
268
-
269
- def includeGradleFile = new File (androidDir, " include.gradle" )
270
- def destinationDir = file(" ${ configurationsDir} /${ pluginName} /" )
271
- def destinationIncludeGradleFile = file(" ${ configurationsDir} /${ pluginName} /include.gradle" )
272
-
273
- Files . createDirectories(Paths . get(destinationDir. getAbsolutePath()))
274
-
275
- if (includeGradleFile. exists()) {
276
- println " \t + add include.gradle from ${ includeGradleFile} "
277
- destinationIncludeGradleFile. text = modifyProductFlavorInContent(includeGradleFile. text, dimensionName, flavor)
278
- } else {
279
- println " \t + creating include.gradle for plugin ${ file(dep.directory)} "
280
- destinationIncludeGradleFile. text = createProductFlavorsContent(flavor, dimensionName)
281
- }
282
-
283
- includes. add(destinationIncludeGradleFile. getAbsolutePath());
284
-
285
- copyAndRenamePluginDirToFlavorName(androidDir, flavor);
286
- }
287
-
288
- flavorDimensions(* dimensions)
289
-
290
- includes. each {
291
- println " \t + applying plugin configuration from ${ it} "
292
- apply from : it
293
- }
294
- }
295
-
296
- applyPluginsIncludeGradleConfigurations. finalizedBy(applyAppGradleConfiguration)
297
-
298
- task applyAppGradleConfiguration {
299
- description " applies user-defined gradle configuration"
300
-
301
- def pathToAppGradle = " $projectDir /../../app/App_Resources/Android/app.gradle"
302
- def appGradle = file(pathToAppGradle)
303
- if (appGradle. exists()) {
304
- println " \t + applying user-defined configuration from ${ appGradle} "
305
- apply from : pathToAppGradle
306
- }
307
- }
308
-
309
298
static def updateProductFlavorsContent (flavor , dimensionName , oldContent ) {
310
299
def endIndex = oldContent. length() - 1 ;
311
300
def index = 0 ;
@@ -476,15 +465,15 @@ def copyAndRenamePluginDirToFlavorName(directory, flavor) {
476
465
copyFolder(directory, targetDir)
477
466
}
478
467
479
- // //////////////////////////////////////////////////////////////////////////////////
480
- // /////////////////////////// EXECUTUION PHASE /////////////////////////////////////
481
- // //////////////////////////////////////////////////////////////////////////////////
482
-
483
468
task ensureMetadataOutDir {
484
469
def outputDir = file(" $projectDir /metadata/output/assets/metadata" )
485
470
outputDir. mkdirs()
486
471
}
487
472
473
+ // //////////////////////////////////////////////////////////////////////////////////
474
+ // /////////////////////////// EXECUTUION PHASE /////////////////////////////////////
475
+ // //////////////////////////////////////////////////////////////////////////////////
476
+
488
477
task collectAllJars {
489
478
description " gathers all paths to jar dependencies before building metadata with them"
490
479
0 commit comments