Skip to content

Commit 501f884

Browse files
committed
feat: working gradle7
1 parent 332bf68 commit 501f884

File tree

23 files changed

+2355
-457
lines changed

23 files changed

+2355
-457
lines changed

build-artifacts/project-template-gradle/gradle.properties

+26
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,29 @@ org.gradle.jvmargs=-Xmx16384M
1818

1919
android.enableJetifier=true
2020
android.useAndroidX=true
21+
22+
23+
BUILD_TOOLS_VERSION=31.0.0
24+
COMPILE_SDK_VERSION=31
25+
MIN_SDK_VERSION=19
26+
ANDRIOD_BUILD_TOOLS_VERSION = 7.0.2
27+
28+
gson_version = 2.8.6
29+
bcel_version = 6.2
30+
junit_version = 4.13.2
31+
mockito_core_version = 3.0.0
32+
kotlin_version = 1.5.21
33+
kotlinx_metadata_jvm_version = 0.3.0
34+
android_x_app_compat_version = 1.3.1
35+
android_x_material_version = 1.4.0
36+
android_x_exif_interface_version = 1.3.2
37+
android_x_view_pager_version = 1.0.0
38+
android_x_fragment_version = 1.3.6
39+
android_x_transition_version = 1.4.1
40+
android_x_multidex_version = 2.0.1
41+
commons_io_version = 2.6
42+
spotbugs_version = 3.1.12
43+
google_java_format_version = 1.6
44+
json_version = 20180813
45+
asm_util_version = 7.0
46+
asm_version = 7.0

build.gradle

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import groovy.json.JsonOutput
1616

1717
def onlyX86 = project.hasProperty("onlyX86")
1818
def useCCache = !project.hasProperty("noCCache")
19+
def hasNdkVersion = project.hasProperty("ndkVersion")
20+
21+
if (hasNdkVersion) {
22+
println "Using NDK version " + ndkVersion
23+
}
1924

2025
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
2126
def pVersion = "no package version was provided by build.gradle build"
@@ -36,6 +41,11 @@ task checkEnvironmentVariables {
3641
throw new GradleException("Set ANDROID_HOME to point to the correct Android SDK location\n")
3742
}
3843

44+
if ("$System.env.ANDROID_NDK_HOME" == "" || "$System.env.ANDROID_NDK_HOME" == "null" && !project.hasProperty("ndkVersion")) {
45+
logger.warn("Warning: The ANDROID_NDK_HOME is not set nor the ndkVersion project property. The build might fail if a ndk cannot be found.\n")
46+
}
47+
48+
3949
if ("$System.env.GIT_COMMIT" == "null" && !project.hasProperty("gitCommitVersion")) {
4050
logger.warn("Warning: The GIT_COMMIT is not set. This NativeScript Android Runtime will not be tagged with the git commit it is build from\n")
4151
}
@@ -185,6 +195,9 @@ def getAssembleReleaseBuildArguments = { ->
185195
if (useCCache) {
186196
arguments.add("-PuseCCache")
187197
}
198+
if (hasNdkVersion) {
199+
arguments.add("-PndkVersion="+ndkVersion)
200+
}
188201
arguments += ["--warning-mode", "all"]
189202
return arguments
190203
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

test-app/app/build.gradle

+43-132
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323

2424
import groovy.io.FileType
2525
import groovy.json.JsonSlurper
26+
import org.apache.commons.io.FileUtils
2627

2728
import javax.inject.Inject
2829
import java.nio.file.Files
2930
import java.nio.file.Paths
3031
import java.nio.file.StandardCopyOption
3132
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+
3337
import static org.gradle.internal.logging.text.StyledTextOutput.Style
3438

3539
apply plugin: "com.android.application"
@@ -41,7 +45,7 @@ def enableKotlin = (project.hasProperty("useKotlin") && project.useKotlin == "tr
4145

4246
if (enableKotlin) {
4347
apply plugin: 'kotlin-android'
44-
apply plugin: 'kotlin-android-extensions'
48+
apply plugin: 'kotlin-parcelize'
4549
}
4650

4751
def onlyX86 = project.hasProperty("onlyX86")
@@ -78,11 +82,11 @@ def METADATA_OUT_PATH = "$projectDir/src/main/assets/metadata"
7882
def pluginsJarLibraries = new LinkedList<String>()
7983
def allJarLibraries = new LinkedList<String>()
8084

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 }
8488
def computeBuildToolsVersion = { ->
85-
project.hasProperty("buildToolsVersion") ? buildToolsVersion : "29.0.2"
89+
project.hasProperty("buildToolsVersion") ? buildToolsVersion : BUILD_TOOLS_VERSION as String
8690
}
8791

8892
def enableAnalytics = (project.hasProperty("gatherAnalyticsData") && project.gatherAnalyticsData == "true")
@@ -97,76 +101,6 @@ if (enableAnalytics) {
97101
project.ext.selectedBuildType = project.hasProperty("release") ? "release" : "debug"
98102

99103
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-
}
170104
def applyBuildScriptConfigurations = { ->
171105
def absolutePathToAppResources = getAppResourcesPath()
172106
def pathToBuildScriptGradle = "$absolutePathToAppResources/Android/buildscript.gradle"
@@ -185,8 +119,6 @@ version of the {N} CLI install a previous version of the runtime package - 'tns
185119
}
186120
}
187121
}
188-
189-
initialize()
190122
applyBuildScriptConfigurations()
191123
}
192124
////////////////////////////////////////////////////////////////////////////////////
@@ -266,7 +198,7 @@ android {
266198

267199
defaultConfig {
268200
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
270202
minSdkVersion minSdkVer
271203
targetSdkVersion computeTargetSdkVersion()
272204
ndk {
@@ -276,9 +208,6 @@ android {
276208
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
277209
}
278210
}
279-
dexOptions {
280-
jumboMode = true
281-
}
282211
}
283212

284213
compileOptions {
@@ -373,54 +302,55 @@ repositories {
373302
}
374303

375304
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-
}
381305

382-
def androidXAppCompatVersion = "1.1.0"
306+
def androidXAppCompatVersion = "${android_x_app_compat_version}"
383307
if (project.hasProperty("androidXAppCompat")) {
384308
androidXAppCompatVersion = androidXAppCompat
385309
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library androidx.appcompat:appcompat:$androidXAppCompatVersion"
386310
}
387311

388-
def androidXMaterialVersion = "1.1.0"
312+
def androidXMaterialVersion = "${android_x_material_version}"
389313
if (project.hasProperty("androidXMaterial")) {
390314
androidXMaterialVersion = androidXMaterial
391315
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library com.google.android.material:material:$androidXMaterialVersion"
392316
}
393317

394-
def androidXExifInterfaceVersion = "1.2.0"
318+
def androidXExifInterfaceVersion = "${android_x_exif_interface_version}"
395319
if (project.hasProperty("androidXExifInterface")) {
396320
androidXExifInterfaceVersion = androidXExifInterface
397321
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library androidx.exifinterface:exifinterface:$androidXExifInterfaceVersion"
398322
}
399323

400-
def androidXViewPagerVersion = "1.0.0"
324+
def androidXViewPagerVersion = "${android_x_view_pager_version}"
401325
if (project.hasProperty("androidXViewPager")) {
402326
androidXViewPagerVersion = androidXViewPager
403327
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library androidx.viewpager2:viewpager2:$androidXViewPagerVersion"
404328
}
405329

406-
def androidXFragmentVersion = "1.2.5"
330+
def androidXFragmentVersion = "${android_x_fragment_version}"
407331
if (project.hasProperty("androidXFragment")) {
408332
androidXFragmentVersion = androidXFragment
409333
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library androidx.fragment:fragment:$androidXFragmentVersion"
410334
}
411335

412-
def androidXTransitionVersion = "1.3.1"
336+
def androidXTransitionVersion = "${android_x_transition_version}"
413337
if (project.hasProperty("androidXTransition")) {
414338
androidXTransitionVersion = androidXTransition
415339
outLogger.withStyle(Style.SuccessHeader).println "\t + using android X library androidx.transition:transition:$androidXTransitionVersion"
416340
}
417341

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"
420349
implementation "androidx.appcompat:appcompat:$androidXAppCompatVersion"
421350
implementation "com.google.android.material:material:$androidXMaterialVersion"
422351
implementation "androidx.exifinterface:exifinterface:$androidXExifInterfaceVersion"
423352
implementation "androidx.viewpager2:viewpager2:$androidXViewPagerVersion"
353+
//noinspection KtxExtensionAvailable
424354
implementation "androidx.fragment:fragment:$androidXFragmentVersion"
425355
implementation "androidx.transition:transition:$androidXTransitionVersion"
426356

@@ -520,7 +450,7 @@ if (failOnCompilationWarningsEnabled()) {
520450
}
521451
}
522452

523-
tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
453+
tasks.whenTaskAdded({ DefaultTask currentTask ->
524454
if (currentTask =~ /generate.+BuildConfig/) {
525455
currentTask.finalizedBy(extractAllJars)
526456
extractAllJars.finalizedBy(collectAllJars)
@@ -530,7 +460,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
530460
currentTask.finalizedBy(buildMetadata)
531461
}
532462
if (currentTask =~ /merge.*Assets/) {
533-
currentTask.shouldRunAfter(buildMetadata)
463+
currentTask.dependsOn(buildMetadata)
534464
}
535465
if (currentTask =~ /assemble.*Debug/ || currentTask =~ /assemble.*Release/) {
536466
currentTask.finalizedBy("validateAppIdMatch")
@@ -578,19 +508,19 @@ def explodeAar(File compileDependency, File outputDir) {
578508
logger.info("explodeAar: Extracting ${compileDependency.path} -> ${outputDir.path}")
579509

580510
if (compileDependency.name.endsWith(".aar")) {
581-
java.util.jar.JarFile jar = new java.util.jar.JarFile(compileDependency)
511+
JarFile jar = new JarFile(compileDependency)
582512
Enumeration enumEntries = jar.entries()
583513
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+
}
585518
if (file.name.endsWith(".jar")) {
586519
def targetFile = new File(outputDir, file.name)
587520
InputStream inputStream = jar.getInputStream(file)
588521
new File(targetFile.parent).mkdirs()
589522
Files.copy(inputStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
590523
}
591-
if (file.isDirectory()) {
592-
continue
593-
}
594524
}
595525
jar.close()
596526
} else if (compileDependency.name.endsWith(".jar")) {
@@ -629,34 +559,15 @@ def getMergedAssetsOutputPath() {
629559

630560
// Discover all jars and dynamically create tasks for the extraction of each of them
631561
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)
660571
}
661572
}
662573
}
@@ -718,7 +629,7 @@ task cleanupAllJars {
718629
// An old directory which is no longer a dependency (e.g. orphaned by a deleted plugin)
719630
if (!allDests.contains(it.name)) {
720631
logger.info("Task cleanupAllJars: Deleting orphaned ${it.path}")
721-
org.apache.commons.io.FileUtils.deleteDirectory(it)
632+
FileUtils.deleteDirectory(it)
722633
}
723634
}
724635
}
@@ -836,7 +747,7 @@ task buildMetadata(type: BuildToolTask) {
836747

837748
def generatedClasses = new LinkedList<String>()
838749
for (File subDir : classesSubDirs) {
839-
if (subDir.getName().equals(selectedBuildType)) {
750+
if (subDir.getName() == selectedBuildType) {
840751
generatedClasses.add(subDir.getAbsolutePath())
841752
}
842753
}

0 commit comments

Comments
 (0)