@@ -27,8 +27,13 @@ import java.nio.file.Files
27
27
import java.nio.file.Paths
28
28
import java.nio.file.StandardCopyOption
29
29
import java.security.MessageDigest
30
+ import org.gradle.internal.logging.text.StyledTextOutputFactory
31
+ import static org.gradle.internal.logging.text.StyledTextOutput.Style
30
32
31
33
apply plugin : " com.android.application"
34
+ apply from : " gradle-helpers/BuildToolTask.gradle"
35
+ apply from : " gradle-helpers/CustomExecutionLogger.gradle"
36
+ apply from : " gradle-helpers/AnalyticsCollector.gradle"
32
37
33
38
def enableKotlin = (project. hasProperty(" useKotlin" ) && project. useKotlin == " true" )
34
39
@@ -39,7 +44,7 @@ if (enableKotlin) {
39
44
40
45
def onlyX86 = project. hasProperty(" onlyX86" )
41
46
if (onlyX86) {
42
- println " OnlyX86 build triggered."
47
+ outLogger . withStyle( Style.Info ) . println " OnlyX86 build triggered."
43
48
}
44
49
45
50
// common
@@ -78,6 +83,14 @@ def computeBuildToolsVersion = { ->
78
83
project. hasProperty(" buildToolsVersion" ) ? buildToolsVersion : " 29.0.2"
79
84
}
80
85
86
+ def enableAnalytics = (project. hasProperty(" gatherAnalyticsData" ) && project. gatherAnalyticsData == " true" )
87
+ def analyticsFilePath = " $rootDir /analytics/build-statistics.json"
88
+ def analyticsCollector = project.ext.AnalyticsCollector . withOutputPath(analyticsFilePath)
89
+ if (enableKotlin && enableAnalytics) {
90
+ analyticsCollector. markHasUseKotlinPropertyInApp()
91
+ analyticsCollector. writeAnalyticsFile()
92
+ }
93
+
81
94
project. ext. selectedBuildType = project. hasProperty(" release" ) ? " release" : " debug"
82
95
83
96
buildscript {
@@ -100,6 +113,7 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
100
113
project. ext. nativescriptDependencies = new JsonSlurper (). parseText(dependenciesJson. text)
101
114
project. ext. PLATFORMS_ANDROID = " platforms/android"
102
115
project. ext. USER_PROJECT_ROOT = " $rootDir /../.."
116
+ project. ext. outLogger = services. get(StyledTextOutputFactory ). create(" colouredOutputLogger" )
103
117
104
118
project. ext. getAppPath = { ->
105
119
def relativePathToApp = " app"
@@ -146,15 +160,15 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
146
160
def pathToBuildScriptGradle = " $absolutePathToAppResources /Android/buildscript.gradle"
147
161
def buildScriptGradle = file(pathToBuildScriptGradle)
148
162
if (buildScriptGradle. exists()) {
149
- println " \t + applying user-defined buildscript from ${ buildScriptGradle} "
163
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + applying user-defined buildscript from ${ buildScriptGradle} "
150
164
apply from : pathToBuildScriptGradle, to : buildscript
151
165
}
152
166
153
167
nativescriptDependencies. each { dep ->
154
168
def pathToPluginBuildScriptGradle = " $rootDir /${ dep.directory} /$PLATFORMS_ANDROID /buildscript.gradle"
155
169
def pluginBuildScriptGradle = file(pathToPluginBuildScriptGradle)
156
170
if (pluginBuildScriptGradle. exists()) {
157
- println " \t + applying user-defined buildscript from dependency ${ pluginBuildScriptGradle} "
171
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + applying user-defined buildscript from dependency ${ pluginBuildScriptGradle} "
158
172
apply from : pathToPluginBuildScriptGradle, to : buildscript
159
173
}
160
174
}
@@ -172,7 +186,7 @@ def applyBeforePluginGradleConfiguration = { ->
172
186
def pathToBeforePluginGradle = " $appResourcesPath /Android/before-plugins.gradle"
173
187
def beforePluginGradle = file(pathToBeforePluginGradle)
174
188
if (beforePluginGradle. exists()) {
175
- println " \t + applying user-defined configuration from ${ beforePluginGradle} "
189
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + applying user-defined configuration from ${ beforePluginGradle} "
176
190
apply from : pathToBeforePluginGradle
177
191
}
178
192
}
@@ -182,10 +196,10 @@ def applyAppGradleConfiguration = { ->
182
196
def pathToAppGradle = " $appResourcesPath /Android/app.gradle"
183
197
def appGradle = file(pathToAppGradle)
184
198
if (appGradle. exists()) {
185
- println " \t + applying user-defined configuration from ${ appGradle} "
199
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + applying user-defined configuration from ${ appGradle} "
186
200
apply from : pathToAppGradle
187
201
} else {
188
- println " \t + couldn't load user-defined configuration from ${ appGradle} . File doesn't exist."
202
+ outLogger . withStyle( Style.Info ) . println " \t + couldn't load user-defined configuration from ${ appGradle} . File doesn't exist."
189
203
}
190
204
}
191
205
@@ -211,7 +225,7 @@ def getAppIdentifier = { packageJsonMap ->
211
225
}
212
226
213
227
def setAppIdentifier = { ->
214
- println " \t + setting applicationId"
228
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + setting applicationId"
215
229
File packageJsonFile = new File (" $USER_PROJECT_ROOT /$PACKAGE_JSON " )
216
230
217
231
if (packageJsonFile. exists()) {
@@ -261,7 +275,7 @@ android {
261
275
}
262
276
263
277
sourceSets. main {
264
- jniLibs. srcDir " $projectDir /libs/jni"
278
+ jniLibs. srcDirs = [ " $projectDir /libs/jni" , " $p rojectDir /snapshot-build/build/ndk-build/libs " ]
265
279
}
266
280
267
281
signingConfigs {
@@ -303,7 +317,7 @@ android {
303
317
task = variant. getMergeAssets()
304
318
}
305
319
for (File file : task. getOutputs(). getFiles()) {
306
- if (! file. getPath(). contains(" / incremental/ " )) {
320
+ if (! file. getPath(). contains(" ${ File.separator } incremental${ File.separator } " )) {
307
321
project. ext. mergedAssetsOutputPath = file. getPath()
308
322
break ;
309
323
}
@@ -362,7 +376,7 @@ dependencies {
362
376
androidXMaterialVersion = androidXMaterial
363
377
}
364
378
365
- println " \t + using android X library androidx.legacy:legacy-support-v4:$androidXLegacyVersion "
379
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + using android X library androidx.legacy:legacy-support-v4:$androidXLegacyVersion "
366
380
367
381
implementation " androidx.multidex:multidex:2.0.1"
368
382
implementation " androidx.legacy:legacy-support-v4:$androidXLegacyVersion "
@@ -397,7 +411,7 @@ dependencies {
397
411
runtime = " nativescript-regular"
398
412
}
399
413
400
- println " \t + adding nativescript runtime package dependency: $runtime "
414
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding nativescript runtime package dependency: $runtime "
401
415
project. dependencies. add(" implementation" , [name : runtime, ext : " aar" ])
402
416
} else {
403
417
implementation project(' :runtime' )
@@ -420,14 +434,14 @@ task addDependenciesFromNativeScriptPlugins {
420
434
aarFiles. each { aarFile ->
421
435
def length = aarFile. name. length() - 4
422
436
def fileName = aarFile. name[0 .. < length]
423
- println " \t + adding aar plugin dependency: " + aarFile. getAbsolutePath()
437
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding aar plugin dependency: " + aarFile. getAbsolutePath()
424
438
project. dependencies. add(" implementation" , [name : fileName, ext : " aar" ])
425
439
}
426
440
427
441
def jarFiles = fileTree(dir : file(" $rootDir /${ dep.directory} /$PLATFORMS_ANDROID " ), include : [" **/*.jar" ])
428
442
jarFiles. each { jarFile ->
429
443
def jarFileAbsolutePath = jarFile. getAbsolutePath()
430
- println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
444
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
431
445
pluginsJarLibraries. add(jarFile. getAbsolutePath())
432
446
}
433
447
@@ -443,14 +457,14 @@ task addDependenciesFromAppResourcesLibraries {
443
457
aarFiles. each { aarFile ->
444
458
def length = aarFile. name. length() - 4
445
459
def fileName = aarFile. name[0 .. < length]
446
- println " \t + adding aar library dependency: " + aarFile. getAbsolutePath()
460
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding aar library dependency: " + aarFile. getAbsolutePath()
447
461
project. dependencies. add(" implementation" , [name : fileName, ext : " aar" ])
448
462
}
449
463
450
464
def jarFiles = fileTree(dir : appResourcesLibraries, include : [" **/*.jar" ])
451
465
jarFiles. each { jarFile ->
452
466
def jarFileAbsolutePath = jarFile. getAbsolutePath()
453
- println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
467
+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
454
468
pluginsJarLibraries. add(jarFile. getAbsolutePath())
455
469
}
456
470
@@ -486,7 +500,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
486
500
// /////////////////////////// EXECUTUION PHASE /////////////////////////////////////
487
501
// //////////////////////////////////////////////////////////////////////////////////
488
502
489
- task runSbg (type : JavaExec ) {
503
+ task runSbg (type : BuildToolTask ) {
490
504
dependsOn " collectAllJars"
491
505
if (! findProject(' :static-binding-generator' ). is(null )) {
492
506
dependsOn ' :static-binding-generator:jar'
@@ -506,6 +520,8 @@ task runSbg(type: JavaExec) {
506
520
paramz. add(" -show-deprecation-warnings" )
507
521
}
508
522
523
+ setOutputs outLogger
524
+
509
525
args paramz
510
526
511
527
doFirst {
@@ -564,7 +580,7 @@ class EmptyRunnable implements Runnable {
564
580
565
581
def getMergedAssetsOutputPath () {
566
582
if (! project. hasProperty(" mergedAssetsOutputPath" )) {
567
- // mergedAssetsOutputPath not found fallback to the default value for android gradle plugin 3.5.0
583
+ // mergedAssetsOutputPath not found fallback to the default value for android gradle plugin 3.5.1
568
584
project. ext. mergedAssetsOutputPath = " $projectDir /build/intermediates/merged_assets/" + project. selectedBuildType + " /out"
569
585
}
570
586
return project. ext. mergedAssetsOutputPath
@@ -599,7 +615,7 @@ afterEvaluate { project ->
599
615
}
600
616
}
601
617
} else {
602
- println " WARNING: Folder ${ jarDir.path} does not exists, the dependent project's classes won't be included in the metadata"
618
+ outLogger . withStyle( Style.Info ) . println " WARNING: Folder ${ jarDir.path} does not exists, the dependent project's classes won't be included in the metadata"
603
619
}
604
620
}
605
621
}
@@ -727,7 +743,7 @@ task copyMetadata {
727
743
}
728
744
}
729
745
730
- task buildMetadata (type : JavaExec ) {
746
+ task buildMetadata (type : BuildToolTask ) {
731
747
if (! findProject(' :android-metadata-generator' ). is(null )) {
732
748
dependsOn ' :android-metadata-generator:jar'
733
749
}
@@ -791,11 +807,20 @@ task buildMetadata(type: JavaExec) {
791
807
workingDir " $BUILD_TOOLS_PATH "
792
808
main " -jar"
793
809
794
- args " android-metadata-generator.jar"
810
+ setOutputs outLogger
811
+
812
+ def paramz = new ArrayList<String > ()
813
+ paramz. add(" android-metadata-generator.jar" )
814
+
815
+ if (enableAnalytics){
816
+ paramz. add(" analyticsFilePath=$analyticsFilePath " )
817
+ }
818
+
819
+ args paramz. toArray()
795
820
}
796
821
}
797
822
798
- task generateTypescriptDefinitions (type : JavaExec ) {
823
+ task generateTypescriptDefinitions (type : BuildToolTask ) {
799
824
if (! findProject(' :dts-generator' ). is(null )) {
800
825
dependsOn ' :dts-generator:jar'
801
826
}
@@ -826,7 +851,10 @@ task generateTypescriptDefinitions(type: JavaExec) {
826
851
new File (" $TYPINGS_PATH " ). mkdirs()
827
852
828
853
logger. info(" Task generateTypescriptDefinitions: Call dts-generator.jar with arguments: " + paramz. toString(). replaceAll(' ,' , ' ' ))
829
- println " Task generateTypescriptDefinitions: Call dts-generator.jar with arguments: " + paramz. toString(). replaceAll(' ,' , ' ' )
854
+ outLogger. withStyle(Style.SuccessHeader ). println " Task generateTypescriptDefinitions: Call dts-generator.jar with arguments: " + paramz. toString(). replaceAll(' ,' , ' ' )
855
+
856
+ setOutputs outLogger
857
+
830
858
args paramz. toArray()
831
859
}
832
860
}
@@ -849,7 +877,7 @@ static def shouldIncludeDirForTypings(path, includeDirs) {
849
877
850
878
task copyTypings {
851
879
doLast {
852
- println " Copied generated typings to application root level. Make sure to import android.d.ts in reference.d.ts"
880
+ outLogger . withStyle( Style.Info ) . println " Copied generated typings to application root level. Make sure to import android.d.ts in reference.d.ts"
853
881
854
882
copy {
855
883
from " $TYPINGS_PATH "
0 commit comments