@@ -27,8 +27,13 @@ import java.nio.file.Files
2727import java.nio.file.Paths
2828import java.nio.file.StandardCopyOption
2929import java.security.MessageDigest
30+ import org.gradle.internal.logging.text.StyledTextOutputFactory
31+ import static org.gradle.internal.logging.text.StyledTextOutput.Style
3032
3133apply 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"
3237
3338def enableKotlin = (project. hasProperty(" useKotlin" ) && project. useKotlin == " true" )
3439
@@ -39,7 +44,7 @@ if (enableKotlin) {
3944
4045def onlyX86 = project. hasProperty(" onlyX86" )
4146if (onlyX86) {
42- println " OnlyX86 build triggered."
47+ outLogger . withStyle( Style.Info ) . println " OnlyX86 build triggered."
4348}
4449
4550// common
@@ -78,6 +83,14 @@ def computeBuildToolsVersion = { ->
7883 project. hasProperty(" buildToolsVersion" ) ? buildToolsVersion : " 29.0.2"
7984}
8085
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+
8194project. ext. selectedBuildType = project. hasProperty(" release" ) ? " release" : " debug"
8295
8396buildscript {
@@ -100,6 +113,7 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
100113 project. ext. nativescriptDependencies = new JsonSlurper (). parseText(dependenciesJson. text)
101114 project. ext. PLATFORMS_ANDROID = " platforms/android"
102115 project. ext. USER_PROJECT_ROOT = " $rootDir /../.."
116+ project. ext. outLogger = services. get(StyledTextOutputFactory ). create(" colouredOutputLogger" )
103117
104118 project. ext. getAppPath = { ->
105119 def relativePathToApp = " app"
@@ -146,15 +160,15 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
146160 def pathToBuildScriptGradle = " $absolutePathToAppResources /Android/buildscript.gradle"
147161 def buildScriptGradle = file(pathToBuildScriptGradle)
148162 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} "
150164 apply from : pathToBuildScriptGradle, to : buildscript
151165 }
152166
153167 nativescriptDependencies. each { dep ->
154168 def pathToPluginBuildScriptGradle = " $rootDir /${ dep.directory} /$PLATFORMS_ANDROID /buildscript.gradle"
155169 def pluginBuildScriptGradle = file(pathToPluginBuildScriptGradle)
156170 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} "
158172 apply from : pathToPluginBuildScriptGradle, to : buildscript
159173 }
160174 }
@@ -172,7 +186,7 @@ def applyBeforePluginGradleConfiguration = { ->
172186 def pathToBeforePluginGradle = " $appResourcesPath /Android/before-plugins.gradle"
173187 def beforePluginGradle = file(pathToBeforePluginGradle)
174188 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} "
176190 apply from : pathToBeforePluginGradle
177191 }
178192}
@@ -182,10 +196,10 @@ def applyAppGradleConfiguration = { ->
182196 def pathToAppGradle = " $appResourcesPath /Android/app.gradle"
183197 def appGradle = file(pathToAppGradle)
184198 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} "
186200 apply from : pathToAppGradle
187201 } 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."
189203 }
190204}
191205
@@ -211,7 +225,7 @@ def getAppIdentifier = { packageJsonMap ->
211225}
212226
213227def setAppIdentifier = { ->
214- println " \t + setting applicationId"
228+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + setting applicationId"
215229 File packageJsonFile = new File (" $USER_PROJECT_ROOT /$PACKAGE_JSON " )
216230
217231 if (packageJsonFile. exists()) {
@@ -261,7 +275,7 @@ android {
261275 }
262276
263277 sourceSets. main {
264- jniLibs. srcDir " $projectDir /libs/jni"
278+ jniLibs. srcDirs = [ " $projectDir /libs/jni" , " $p rojectDir /snapshot-build/build/ndk-build/libs " ]
265279 }
266280
267281 signingConfigs {
@@ -303,7 +317,7 @@ android {
303317 task = variant. getMergeAssets()
304318 }
305319 for (File file : task. getOutputs(). getFiles()) {
306- if (! file. getPath(). contains(" / incremental/ " )) {
320+ if (! file. getPath(). contains(" ${ File.separator } incremental${ File.separator } " )) {
307321 project. ext. mergedAssetsOutputPath = file. getPath()
308322 break ;
309323 }
@@ -362,7 +376,7 @@ dependencies {
362376 androidXMaterialVersion = androidXMaterial
363377 }
364378
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 "
366380
367381 implementation " androidx.multidex:multidex:2.0.1"
368382 implementation " androidx.legacy:legacy-support-v4:$androidXLegacyVersion "
@@ -397,7 +411,7 @@ dependencies {
397411 runtime = " nativescript-regular"
398412 }
399413
400- println " \t + adding nativescript runtime package dependency: $runtime "
414+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding nativescript runtime package dependency: $runtime "
401415 project. dependencies. add(" implementation" , [name : runtime, ext : " aar" ])
402416 } else {
403417 implementation project(' :runtime' )
@@ -420,14 +434,14 @@ task addDependenciesFromNativeScriptPlugins {
420434 aarFiles. each { aarFile ->
421435 def length = aarFile. name. length() - 4
422436 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()
424438 project. dependencies. add(" implementation" , [name : fileName, ext : " aar" ])
425439 }
426440
427441 def jarFiles = fileTree(dir : file(" $rootDir /${ dep.directory} /$PLATFORMS_ANDROID " ), include : [" **/*.jar" ])
428442 jarFiles. each { jarFile ->
429443 def jarFileAbsolutePath = jarFile. getAbsolutePath()
430- println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
444+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
431445 pluginsJarLibraries. add(jarFile. getAbsolutePath())
432446 }
433447
@@ -443,14 +457,14 @@ task addDependenciesFromAppResourcesLibraries {
443457 aarFiles. each { aarFile ->
444458 def length = aarFile. name. length() - 4
445459 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()
447461 project. dependencies. add(" implementation" , [name : fileName, ext : " aar" ])
448462 }
449463
450464 def jarFiles = fileTree(dir : appResourcesLibraries, include : [" **/*.jar" ])
451465 jarFiles. each { jarFile ->
452466 def jarFileAbsolutePath = jarFile. getAbsolutePath()
453- println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
467+ outLogger . withStyle( Style.SuccessHeader ) . println " \t + adding jar plugin dependency: $jarFileAbsolutePath "
454468 pluginsJarLibraries. add(jarFile. getAbsolutePath())
455469 }
456470
@@ -486,7 +500,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
486500// /////////////////////////// EXECUTUION PHASE /////////////////////////////////////
487501// //////////////////////////////////////////////////////////////////////////////////
488502
489- task runSbg (type : JavaExec ) {
503+ task runSbg (type : BuildToolTask ) {
490504 dependsOn " collectAllJars"
491505 if (! findProject(' :static-binding-generator' ). is(null )) {
492506 dependsOn ' :static-binding-generator:jar'
@@ -506,6 +520,8 @@ task runSbg(type: JavaExec) {
506520 paramz. add(" -show-deprecation-warnings" )
507521 }
508522
523+ setOutputs outLogger
524+
509525 args paramz
510526
511527 doFirst {
@@ -564,7 +580,7 @@ class EmptyRunnable implements Runnable {
564580
565581def getMergedAssetsOutputPath () {
566582 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
568584 project. ext. mergedAssetsOutputPath = " $projectDir /build/intermediates/merged_assets/" + project. selectedBuildType + " /out"
569585 }
570586 return project. ext. mergedAssetsOutputPath
@@ -599,7 +615,7 @@ afterEvaluate { project ->
599615 }
600616 }
601617 } 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"
603619 }
604620 }
605621 }
@@ -727,7 +743,7 @@ task copyMetadata {
727743 }
728744}
729745
730- task buildMetadata (type : JavaExec ) {
746+ task buildMetadata (type : BuildToolTask ) {
731747 if (! findProject(' :android-metadata-generator' ). is(null )) {
732748 dependsOn ' :android-metadata-generator:jar'
733749 }
@@ -791,11 +807,20 @@ task buildMetadata(type: JavaExec) {
791807 workingDir " $BUILD_TOOLS_PATH "
792808 main " -jar"
793809
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()
795820 }
796821}
797822
798- task generateTypescriptDefinitions (type : JavaExec ) {
823+ task generateTypescriptDefinitions (type : BuildToolTask ) {
799824 if (! findProject(' :dts-generator' ). is(null )) {
800825 dependsOn ' :dts-generator:jar'
801826 }
@@ -826,7 +851,10 @@ task generateTypescriptDefinitions(type: JavaExec) {
826851 new File (" $TYPINGS_PATH " ). mkdirs()
827852
828853 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+
830858 args paramz. toArray()
831859 }
832860}
@@ -849,7 +877,7 @@ static def shouldIncludeDirForTypings(path, includeDirs) {
849877
850878task copyTypings {
851879 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"
853881
854882 copy {
855883 from " $TYPINGS_PATH "
0 commit comments