23
23
24
24
import groovy.io.FileType
25
25
import groovy.json.JsonSlurper
26
+ import org.apache.commons.io.FileUtils
26
27
27
28
import javax.inject.Inject
28
29
import java.nio.file.Files
29
30
import java.nio.file.Paths
30
31
import java.nio.file.StandardCopyOption
31
32
import java.security.MessageDigest
32
- import org.gradle.internal.logging.text.StyledTextOutputFactory
33
+
34
+ import java.util.jar.JarEntry
35
+ import java.util.jar.JarFile
36
+
33
37
import static org.gradle.internal.logging.text.StyledTextOutput.Style
34
38
35
39
apply plugin : " com.android.application"
@@ -41,7 +45,7 @@ def enableKotlin = (project.hasProperty("useKotlin") && project.useKotlin == "tr
41
45
42
46
if (enableKotlin) {
43
47
apply plugin : ' kotlin-android'
44
- apply plugin : ' kotlin-android-extensions '
48
+ apply plugin : ' kotlin-parcelize '
45
49
}
46
50
47
51
def onlyX86 = project. hasProperty(" onlyX86" )
@@ -78,11 +82,11 @@ def METADATA_OUT_PATH = "$projectDir/src/main/assets/metadata"
78
82
def pluginsJarLibraries = new LinkedList<String > ()
79
83
def allJarLibraries = new LinkedList<String > ()
80
84
81
- def computeKotlinVersion = { -> project. hasProperty(" kotlinVersion" ) ? kotlinVersion : " 1.3.41 " }
82
- def computeCompileSdkVersion = { -> project. hasProperty(" compileSdk" ) ? compileSdk : 29 }
83
- def computeTargetSdkVersion = { -> project. hasProperty(" targetSdk" ) ? targetSdk : 29 }
85
+ def computeKotlinVersion = { -> project. hasProperty(" kotlinVersion" ) ? kotlinVersion : " ${ kotlin_version } " }
86
+ def computeCompileSdkVersion = { -> project. hasProperty(" compileSdk" ) ? compileSdk : COMPILE_SDK_VERSION as int }
87
+ def computeTargetSdkVersion = { -> project. hasProperty(" targetSdk" ) ? targetSdk : COMPILE_SDK_VERSION as int }
84
88
def computeBuildToolsVersion = { ->
85
- project. hasProperty(" buildToolsVersion" ) ? buildToolsVersion : " 29.0.2 "
89
+ project. hasProperty(" buildToolsVersion" ) ? buildToolsVersion : BUILD_TOOLS_VERSION as String
86
90
}
87
91
88
92
def enableAnalytics = (project. hasProperty(" gatherAnalyticsData" ) && project. gatherAnalyticsData == " true" )
@@ -97,76 +101,6 @@ if (enableAnalytics) {
97
101
project. ext. selectedBuildType = project. hasProperty(" release" ) ? " release" : " debug"
98
102
99
103
buildscript {
100
- // we have moved these initializations here as we need getAppResourcesPath to search for buildscript.gradle files,
101
- // but the buildscript is executed before executing anything else from the gradle file
102
- def initialize = { ->
103
- // the build script will not work with previous versions of the CLI (3.1 or earlier)
104
- def dependenciesJson = file(" $rootDir /dependencies.json" )
105
- if (! dependenciesJson. exists()) {
106
- throw new BuildCancelledException ("""
107
- 'dependencies.json' file not found. Check whether the NativeScript CLI has prepared the project beforehand,
108
- and that your NativeScript version is 3.3, or a more recent one. To build an android project with the current
109
- version of the {N} CLI install a previous version of the runtime package - 'tns platform add [email protected] '.
110
- """ )
111
- }
112
-
113
- project. ext. extractedDependenciesDir = " ${ project.buildDir} /exploded-dependencies"
114
- project. ext. cleanupAllJarsTimestamp = " ${ project.buildDir} /cleanupAllJars.timestamp"
115
- project. ext. extractAllJarsTimestamp = " ${ project.buildDir} /extractAllJars.timestamp"
116
- project. ext. nativescriptDependencies = new JsonSlurper (). parseText(dependenciesJson. text)
117
- project. ext. PLATFORMS_ANDROID = " platforms/android"
118
- project. ext. USER_PROJECT_ROOT = " $rootDir /../.."
119
- project. ext. outLogger = services. get(StyledTextOutputFactory ). create(" colouredOutputLogger" )
120
-
121
- project. ext. getAppPath = { ->
122
- def relativePathToApp = " app"
123
- def nsConfigFile = file(" $USER_PROJECT_ROOT /nsconfig.json" )
124
- def nsConfig
125
-
126
- if (nsConfigFile. exists()) {
127
- nsConfig = new JsonSlurper (). parseText(nsConfigFile. getText(" UTF-8" ))
128
- }
129
-
130
- if (project. hasProperty(" appPath" )) {
131
- // when appPath is passed through -PappPath=/path/to/app
132
- // the path could be relative or absolute - either case will work
133
- relativePathToApp = appPath
134
- } else if (nsConfig != null && nsConfig. appPath != null ) {
135
- relativePathToApp = nsConfig. appPath
136
- }
137
-
138
- project. ext. appPath = java.nio.file.Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToApp). toAbsolutePath()
139
-
140
- return project. ext. appPath
141
- }
142
-
143
- project. ext. getAppResourcesPath = { ->
144
- def relativePathToAppResources
145
- def absolutePathToAppResources
146
- def nsConfigFile = file(" $USER_PROJECT_ROOT /nsconfig.json" )
147
- def nsConfig
148
-
149
- if (nsConfigFile. exists()) {
150
- nsConfig = new JsonSlurper (). parseText(nsConfigFile. getText(" UTF-8" ))
151
- }
152
-
153
- if (project. hasProperty(" appResourcesPath" )) {
154
- // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources
155
- // the path could be relative or absolute - either case will work
156
- relativePathToAppResources = appResourcesPath
157
- absolutePathToAppResources = java.nio.file.Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToAppResources). toAbsolutePath()
158
- } else if (nsConfig != null && nsConfig. appResourcesPath != null ) {
159
- relativePathToAppResources = nsConfig. appResourcesPath
160
- absolutePathToAppResources = java.nio.file.Paths . get(USER_PROJECT_ROOT ). resolve(relativePathToAppResources). toAbsolutePath()
161
- } else {
162
- absolutePathToAppResources = " ${ getAppPath()} /App_Resources"
163
- }
164
-
165
- project. ext. appResourcesPath = absolutePathToAppResources
166
-
167
- return absolutePathToAppResources
168
- }
169
- }
170
104
def applyBuildScriptConfigurations = { ->
171
105
def absolutePathToAppResources = getAppResourcesPath()
172
106
def pathToBuildScriptGradle = " $absolutePathToAppResources /Android/buildscript.gradle"
@@ -185,8 +119,6 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
185
119
}
186
120
}
187
121
}
188
-
189
- initialize()
190
122
applyBuildScriptConfigurations()
191
123
}
192
124
// //////////////////////////////////////////////////////////////////////////////////
@@ -266,7 +198,7 @@ android {
266
198
267
199
defaultConfig {
268
200
def manifest = new XmlSlurper (). parse(file(android. sourceSets. main. manifest. srcFile))
269
- def minSdkVer = manifest. " uses-sdk" . " @android:minSdkVersion" . text() ?: 17
201
+ def minSdkVer = manifest. " uses-sdk" . " @android:minSdkVersion" . text() ?: MIN_SDK_VERSION
270
202
minSdkVersion minSdkVer
271
203
targetSdkVersion computeTargetSdkVersion()
272
204
ndk {
@@ -276,9 +208,6 @@ android {
276
208
abiFilters ' x86' , ' x86_64' , ' armeabi-v7a' , ' arm64-v8a'
277
209
}
278
210
}
279
- dexOptions {
280
- jumboMode = true
281
- }
282
211
}
283
212
284
213
compileOptions {
@@ -373,54 +302,55 @@ repositories {
373
302
}
374
303
375
304
dependencies {
376
- def androidXLegacyVersion = " 1.0.0"
377
- if (project. hasProperty(" androidXLegacy" )) {
378
- androidXLegacyVersion = androidXLegacy
379
- outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.legacy:legacy-support-v4:$androidXLegacyVersion "
380
- }
381
305
382
- def androidXAppCompatVersion = " 1.1.0 "
306
+ def androidXAppCompatVersion = " ${ android_x_app_compat_version } "
383
307
if (project. hasProperty(" androidXAppCompat" )) {
384
308
androidXAppCompatVersion = androidXAppCompat
385
309
outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.appcompat:appcompat:$androidXAppCompatVersion "
386
310
}
387
311
388
- def androidXMaterialVersion = " 1.1.0 "
312
+ def androidXMaterialVersion = " ${ android_x_material_version } "
389
313
if (project. hasProperty(" androidXMaterial" )) {
390
314
androidXMaterialVersion = androidXMaterial
391
315
outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library com.google.android.material:material:$androidXMaterialVersion "
392
316
}
393
317
394
- def androidXExifInterfaceVersion = " 1.2.0 "
318
+ def androidXExifInterfaceVersion = " ${ android_x_exif_interface_version } "
395
319
if (project. hasProperty(" androidXExifInterface" )) {
396
320
androidXExifInterfaceVersion = androidXExifInterface
397
321
outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.exifinterface:exifinterface:$androidXExifInterfaceVersion "
398
322
}
399
323
400
- def androidXViewPagerVersion = " 1.0.0 "
324
+ def androidXViewPagerVersion = " ${ android_x_view_pager_version } "
401
325
if (project. hasProperty(" androidXViewPager" )) {
402
326
androidXViewPagerVersion = androidXViewPager
403
327
outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.viewpager2:viewpager2:$androidXViewPagerVersion "
404
328
}
405
329
406
- def androidXFragmentVersion = " 1.2.5 "
330
+ def androidXFragmentVersion = " ${ android_x_fragment_version } "
407
331
if (project. hasProperty(" androidXFragment" )) {
408
332
androidXFragmentVersion = androidXFragment
409
333
outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.fragment:fragment:$androidXFragmentVersion "
410
334
}
411
335
412
- def androidXTransitionVersion = " 1.3.1 "
336
+ def androidXTransitionVersion = " ${ android_x_transition_version } "
413
337
if (project. hasProperty(" androidXTransition" )) {
414
338
androidXTransitionVersion = androidXTransition
415
339
outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.transition:transition:$androidXTransitionVersion "
416
340
}
417
341
418
- implementation " androidx.multidex:multidex:2.0.1"
419
- implementation " androidx.legacy:legacy-support-v4:$androidXLegacyVersion "
342
+ def androidXMultidexVersion = " ${ android_x_multidex_version} "
343
+ if (project. hasProperty(" androidXMultidex" )) {
344
+ androidXMultidexVersion = androidXMultidex
345
+ outLogger. withStyle(Style.SuccessHeader ). println " \t + using android X library androidx.multidex:multidex:$androidXMultidexVersion "
346
+ }
347
+
348
+ implementation " androidx.multidex:multidex:$androidXMultidexVersion "
420
349
implementation " androidx.appcompat:appcompat:$androidXAppCompatVersion "
421
350
implementation " com.google.android.material:material:$androidXMaterialVersion "
422
351
implementation " androidx.exifinterface:exifinterface:$androidXExifInterfaceVersion "
423
352
implementation " androidx.viewpager2:viewpager2:$androidXViewPagerVersion "
353
+ // noinspection KtxExtensionAvailable
424
354
implementation " androidx.fragment:fragment:$androidXFragmentVersion "
425
355
implementation " androidx.transition:transition:$androidXTransitionVersion "
426
356
@@ -520,7 +450,7 @@ if (failOnCompilationWarningsEnabled()) {
520
450
}
521
451
}
522
452
523
- tasks. whenTaskAdded({ org.gradle.api. DefaultTask currentTask ->
453
+ tasks. whenTaskAdded({ DefaultTask currentTask ->
524
454
if (currentTask =~ / generate.+BuildConfig/ ) {
525
455
currentTask. finalizedBy(extractAllJars)
526
456
extractAllJars. finalizedBy(collectAllJars)
@@ -530,7 +460,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
530
460
currentTask. finalizedBy(buildMetadata)
531
461
}
532
462
if (currentTask =~ / merge.*Assets/ ) {
533
- currentTask. shouldRunAfter (buildMetadata)
463
+ currentTask. dependsOn (buildMetadata)
534
464
}
535
465
if (currentTask =~ / assemble.*Debug/ || currentTask =~ / assemble.*Release/ ) {
536
466
currentTask. finalizedBy(" validateAppIdMatch" )
@@ -578,19 +508,19 @@ def explodeAar(File compileDependency, File outputDir) {
578
508
logger. info(" explodeAar: Extracting ${ compileDependency.path} -> ${ outputDir.path} " )
579
509
580
510
if (compileDependency. name. endsWith(" .aar" )) {
581
- java.util.jar. JarFile jar = new java.util.jar. JarFile (compileDependency)
511
+ JarFile jar = new JarFile (compileDependency)
582
512
Enumeration enumEntries = jar. entries()
583
513
while (enumEntries. hasMoreElements()) {
584
- java.util.jar.JarEntry file = (java.util.jar.JarEntry ) enumEntries. nextElement()
514
+ JarEntry file = (JarEntry ) enumEntries. nextElement()
515
+ if (file. isDirectory()) {
516
+ continue
517
+ }
585
518
if (file. name. endsWith(" .jar" )) {
586
519
def targetFile = new File (outputDir, file. name)
587
520
InputStream inputStream = jar. getInputStream(file)
588
521
new File (targetFile. parent). mkdirs()
589
522
Files . copy(inputStream, targetFile. toPath(), StandardCopyOption . REPLACE_EXISTING )
590
523
}
591
- if (file. isDirectory()) {
592
- continue
593
- }
594
524
}
595
525
jar. close()
596
526
} else if (compileDependency. name. endsWith(" .jar" )) {
@@ -629,34 +559,15 @@ def getMergedAssetsOutputPath() {
629
559
630
560
// Discover all jars and dynamically create tasks for the extraction of each of them
631
561
project. ext. allJars = []
632
- afterEvaluate { project ->
633
- def buildType = project. selectedBuildType == " release" ? " Release" : " Debug"
634
- def jars = []
635
- def artifactType = Attribute . of(' artifactType' , String )
636
- configurations. all { config ->
637
- if (config. name. toLowerCase(). endsWith(" ${ buildType} RuntimeClasspath" . toLowerCase())) {
638
- config. incoming. artifactView {
639
- attributes {
640
- it. attribute(artifactType, ' jar' )
641
- }
642
- }. artifacts. each {
643
- processJar(it. file, jars)
644
- }
645
-
646
- def projectDependencies = config. getAllDependencies(). withType(ProjectDependency )
647
- def dependentProjects = projectDependencies* . dependencyProject
648
- dependentProjects. findAll {
649
- // if there's a project dependency search for its result jar file in the build/intermediates/runtime_library_classes folder
650
- // this is the output folder in gradle 5.1.1, but it can be changed in the future versions of gradle
651
- def jarDir = new File (" ${ it.getBuildDir()} /intermediates/runtime_library_classes/${ buildType.toLowerCase()} " )
652
- if (jarDir. exists()) {
653
- jarDir. eachFileRecurse(FileType . FILES ) { file ->
654
- if (file. path. endsWith(" .jar" )) {
655
- processJar(file, jars)
656
- }
657
- }
658
- } else {
659
- outLogger. withStyle(Style.Info ). println " WARNING: Folder ${ jarDir.path} does not exists, the dependent project's classes won't be included in the metadata"
562
+ allprojects {
563
+ afterEvaluate { project ->
564
+ def buildType = project. selectedBuildType
565
+ def jars = []
566
+ def artifactType = Attribute . of(' artifactType' , String )
567
+ android. applicationVariants. all { variant ->
568
+ if (variant. buildType. name == buildType) {
569
+ variant. getCompileClasspath(). each { fileDependency ->
570
+ processJar(fileDependency, jars)
660
571
}
661
572
}
662
573
}
@@ -718,7 +629,7 @@ task cleanupAllJars {
718
629
// An old directory which is no longer a dependency (e.g. orphaned by a deleted plugin)
719
630
if (! allDests. contains(it. name)) {
720
631
logger. info(" Task cleanupAllJars: Deleting orphaned ${ it.path} " )
721
- org.apache.commons.io. FileUtils. deleteDirectory(it)
632
+ FileUtils . deleteDirectory(it)
722
633
}
723
634
}
724
635
}
@@ -836,7 +747,7 @@ task buildMetadata(type: BuildToolTask) {
836
747
837
748
def generatedClasses = new LinkedList<String > ()
838
749
for (File subDir : classesSubDirs) {
839
- if (subDir. getName(). equals( selectedBuildType) ) {
750
+ if (subDir. getName() == selectedBuildType) {
840
751
generatedClasses. add(subDir. getAbsolutePath())
841
752
}
842
753
}
0 commit comments