From 4b7c32f32017c406791659475ba066cf5b8903a0 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Thu, 23 Jun 2022 16:01:45 +0200 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20android=20plugins=20now=20built=20us?= =?UTF-8?q?ing=20same=20=E2=80=9Cgradle=E2=80=9D=20as=20apps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * copy paste for now. I think most could be refactored in the runtime and cli should include from there * not kotlin, buildtools, … versions are define like in apps and use same defaults * we dont modify the build.gradle for tempPlugin anymore. Instead we add the plugin as a native dep (to itself..) and just ignore the `aar` that we would build (which can already be there). * now users can do almost anything they want in their plugin `include.gradle` and it will work (for example comments on the first line would break the build) * now while building a tempPlugin we pickup any external aar we find the plugin `platforms` folder (main reason for this change) --- lib/services/android-plugin-build-service.ts | 78 -------- vendor/gradle-plugin/build.gradle | 189 +++++++++++++------ 2 files changed, 127 insertions(+), 140 deletions(-) diff --git a/lib/services/android-plugin-build-service.ts b/lib/services/android-plugin-build-service.ts index ace640be3b..d5ccf7077a 100644 --- a/lib/services/android-plugin-build-service.ts +++ b/lib/services/android-plugin-build-service.ts @@ -144,40 +144,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { return promise; } - private getIncludeGradleCompileDependenciesScope( - includeGradleFileContent: string - ): Array { - const indexOfDependenciesScope = includeGradleFileContent.indexOf( - "dependencies" - ); - const result: Array = []; - - if (indexOfDependenciesScope === -1) { - return result; - } - - const indexOfRepositoriesScope = includeGradleFileContent.indexOf( - "repositories" - ); - - let repositoriesScope = ""; - if (indexOfRepositoriesScope >= 0) { - repositoriesScope = this.getScope( - "repositories", - includeGradleFileContent - ); - result.push(repositoriesScope); - } - - const dependenciesScope = this.getScope( - "dependencies", - includeGradleFileContent - ); - result.push(dependenciesScope); - - return result; - } - private getScope(scopeName: string, content: string): string { const indexOfScopeName = content.indexOf(scopeName); const openingBracket = "{"; @@ -410,7 +376,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { const buildGradlePath = path.join(pluginTempDir, "build.gradle"); this.$fs.copyFile(allGradleTemplateFiles, pluginTempDir); - this.addCompileDependencies(platformsAndroidDirPath, buildGradlePath); const runtimeGradleVersions = await this.getRuntimeGradleVersions( projectDir ); @@ -418,10 +383,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { pluginTempDir, runtimeGradleVersions.gradleVersion ); - this.replaceGradleAndroidPluginVersion( - buildGradlePath, - runtimeGradleVersions.gradleAndroidPluginVersion - ); this.replaceFileContent(buildGradlePath, "{{pluginName}}", pluginName); } @@ -640,22 +601,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { ); } - private replaceGradleAndroidPluginVersion( - buildGradlePath: string, - version: string - ): void { - const gradleAndroidPluginVersionPlaceholder = - "{{runtimeAndroidPluginVersion}}"; - const gradleAndroidPluginVersion = - version || AndroidBuildDefaults.GradleAndroidPluginVersion; - - this.replaceFileContent( - buildGradlePath, - gradleAndroidPluginVersionPlaceholder, - gradleAndroidPluginVersion - ); - } - private replaceFileContent( filePath: string, content: string, @@ -667,29 +612,6 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { this.$fs.writeFile(filePath, replacedFileContent); } - private addCompileDependencies( - platformsAndroidDirPath: string, - buildGradlePath: string - ): void { - const includeGradlePath = path.join( - platformsAndroidDirPath, - INCLUDE_GRADLE_NAME - ); - if (this.$fs.exists(includeGradlePath)) { - const includeGradleContent = this.$fs.readText(includeGradlePath); - const compileDependencies = this.getIncludeGradleCompileDependenciesScope( - includeGradleContent - ); - - if (compileDependencies.length) { - this.$fs.appendFile( - buildGradlePath, - "\n" + compileDependencies.join("\n") - ); - } - } - } - private copyAar( shortPluginName: string, pluginTempDir: string, diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index f18ff4c940..94757d73e0 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -8,85 +8,128 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' buildscript { - def getDepPlatformDir = { dep -> - file("${project.ext.USER_PROJECT_ROOT}/${project.ext.PLATFORMS_ANDROID}/${dep.directory}/$PLATFORMS_ANDROID") - } - def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "1.6.0" } - def kotlinVersion = computeKotlinVersion() - repositories { - google() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:{{runtimeAndroidPluginVersion}}' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + def initialize = { -> + // set up our logger + project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") + outLogger.withStyle(Style.SuccessHeader).println "\t ~initialize" + + + project.ext.USER_PROJECT_ROOT = "$rootDir/../../.." + project.ext.PLATFORMS_ANDROID = "platforms/android" + project.ext.PLUGIN_NAME = "{{pluginName}}" + + def userDir = "$USER_PROJECT_ROOT" + apply from: "$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle-helpers/user_properties_reader.gradle" + apply from: "$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle-helpers/paths.gradle" + rootProject.ext.userDefinedGradleProperties = getUserProperties("${getAppResourcesPath(USER_PROJECT_ROOT)}/Android") + + loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle.properties") + loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/additional_gradle.properties") + + if (rootProject.hasProperty("userDefinedGradleProperties")) { + rootProject.ext.userDefinedGradleProperties.each { entry -> + def propertyName = entry.getKey() + def propertyValue = entry.getValue() + project.ext.set(propertyName, propertyValue) + } + } - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } + def getDepPlatformDir = { dep -> + file("${project.ext.USER_PROJECT_ROOT}/${project.ext.PLATFORMS_ANDROID}/${dep.directory}/$PLATFORMS_ANDROID") + } - // Set up styled logger - project.ext.getDepPlatformDir = getDepPlatformDir - project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") + // Set up styled logger + project.ext.getDepPlatformDir = getDepPlatformDir + project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") - project.ext.USER_PROJECT_ROOT = "$rootDir/../../.." - project.ext.PLATFORMS_ANDROID = "platforms/android" - project.ext.PLUGIN_NAME = "{{pluginName}}" - // the build script will not work with previous versions of the CLI (3.1 or earlier) - def dependenciesJson = file("${project.ext.USER_PROJECT_ROOT}/${project.ext.PLATFORMS_ANDROID}/dependencies.json") - def appDependencies = new JsonSlurper().parseText(dependenciesJson.text) - def pluginData = appDependencies.find { it.name == project.ext.PLUGIN_NAME } - project.ext.nativescriptDependencies = appDependencies.findAll{pluginData.dependencies.contains(it.name)} - project.ext.getAppPath = { -> - def relativePathToApp = "app" - def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") - def nsConfig + // the build script will not work with previous versions of the CLI (3.1 or earlier) + def dependenciesJson = file("${project.ext.USER_PROJECT_ROOT}/${project.ext.PLATFORMS_ANDROID}/dependencies.json") + def appDependencies = new JsonSlurper().parseText(dependenciesJson.text) + def pluginData = appDependencies.find { it.name == project.ext.PLUGIN_NAME } + project.ext.nativescriptDependencies = appDependencies.findAll{pluginData.dependencies.contains(it.name)}.plus([pluginData]) + outLogger.withStyle(Style.SuccessHeader).println "\t ~ nativescriptDependencies ${nativescriptDependencies}" + - if (nsConfigFile.exists()) { - nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) - } + project.ext.getAppResourcesPath = { -> + def relativePathToAppResources + def absolutePathToAppResources + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") + def nsConfig + + if (nsConfigFile.exists()) { + nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + } + + if (project.hasProperty("appResourcesPath")) { + // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources + // the path could be relative or absolute - either case will work + relativePathToAppResources = appResourcesPath + absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() + } else if (nsConfig != null && nsConfig.appResourcesPath != null) { + relativePathToAppResources = nsConfig.appResourcesPath + absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() + } else { + absolutePathToAppResources = "${getAppPath()}/App_Resources" + } + + project.ext.appResourcesPath = absolutePathToAppResources - if (project.hasProperty("appPath")) { - // when appPath is passed through -PappPath=/path/to/app - // the path could be relative or absolute - either case will work - relativePathToApp = appPath - } else if (nsConfig != null && nsConfig.appPath != null) { - relativePathToApp = nsConfig.appPath + return absolutePathToAppResources } - project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath() - return project.ext.appPath - } + project.ext.getAppPath = { -> + def relativePathToApp = "app" + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") + def nsConfig + + if (nsConfigFile.exists()) { + nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + } - project.ext.getAppResourcesPath = { -> - def relativePathToAppResources - def absolutePathToAppResources - def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") - def nsConfig + if (project.hasProperty("appPath")) { + // when appPath is passed through -PappPath=/path/to/app + // the path could be relative or absolute - either case will work + relativePathToApp = appPath + } else if (nsConfig != null && nsConfig.appPath != null) { + relativePathToApp = nsConfig.appPath + } + + project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath() - if (nsConfigFile.exists()) { - nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + return project.ext.appPath } - if (project.hasProperty("appResourcesPath")) { - // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources - // the path could be relative or absolute - either case will work - relativePathToAppResources = appResourcesPath - absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() - } else if (nsConfig != null && nsConfig.appResourcesPath != null) { - relativePathToAppResources = nsConfig.appResourcesPath - absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() - } else { - absolutePathToAppResources = "${getAppPath()}/App_Resources" + project.ext.getAppResourcesPath = { -> + def relativePathToAppResources + def absolutePathToAppResources + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") + def nsConfig + + if (nsConfigFile.exists()) { + nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + } + + if (project.hasProperty("appResourcesPath")) { + // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources + // the path could be relative or absolute - either case will work + relativePathToAppResources = appResourcesPath + absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() + } else if (nsConfig != null && nsConfig.appResourcesPath != null) { + relativePathToAppResources = nsConfig.appResourcesPath + absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() + } else { + absolutePathToAppResources = "${getAppPath()}/App_Resources" + } + + project.ext.appResourcesPath = absolutePathToAppResources + + return absolutePathToAppResources } - project.ext.appResourcesPath = absolutePathToAppResources - return absolutePathToAppResources } - def applyBuildScriptConfigurations = { -> def absolutePathToAppResources = getAppResourcesPath() def pathToBuildScriptGradle = "$absolutePathToAppResources/Android/buildscript.gradle" @@ -112,8 +155,25 @@ buildscript { apply from: pathToPluginBuildScriptGradle, to: buildscript } } + + initialize() applyBuildScriptConfigurations() + def computeKotlinVersion = { -> project.hasProperty("kotlinVersion") ? kotlinVersion : "${ns_default_kotlin_version}" } + def computeBuildToolsVersion = { -> project.hasProperty("androidBuildToolsVersion") ? androidBuildToolsVersion : "${NS_DEFAULT_ANDROID_BUILD_TOOLS_VERSION}" } + def kotlinVersion = computeKotlinVersion() + def androidBuildToolsVersion = computeBuildToolsVersion() + + repositories { + google() + mavenCentral() + } + dependencies { + classpath "com.android.tools.build:gradle:$androidBuildToolsVersion" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + classpath "org.codehaus.groovy:groovy-all:3.0.8" + } + } def pluginDependencies @@ -185,10 +245,15 @@ def applyBeforePluginGradleConfiguration() { task addDependenciesFromNativeScriptPlugins { nativescriptDependencies.each { dep -> + outLogger.withStyle(Style.SuccessHeader).println "\t +addDependenciesFromNativeScriptPlugins: " + getDepPlatformDir(dep) def aarFiles = fileTree(dir: getDepPlatformDir(dep), include: ["**/*.aar"]) + def currentDirname = file(project.buildscript.sourceFile).getParentFile().getName() aarFiles.each { aarFile -> def length = aarFile.name.length() - 4 def fileName = aarFile.name[0.. Date: Thu, 23 Jun 2022 16:05:42 +0200 Subject: [PATCH 2/6] chore: removed logs --- vendor/gradle-plugin/build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 94757d73e0..c2beeb220d 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -48,8 +48,6 @@ buildscript { def appDependencies = new JsonSlurper().parseText(dependenciesJson.text) def pluginData = appDependencies.find { it.name == project.ext.PLUGIN_NAME } project.ext.nativescriptDependencies = appDependencies.findAll{pluginData.dependencies.contains(it.name)}.plus([pluginData]) - outLogger.withStyle(Style.SuccessHeader).println "\t ~ nativescriptDependencies ${nativescriptDependencies}" - project.ext.getAppResourcesPath = { -> def relativePathToAppResources @@ -245,7 +243,6 @@ def applyBeforePluginGradleConfiguration() { task addDependenciesFromNativeScriptPlugins { nativescriptDependencies.each { dep -> - outLogger.withStyle(Style.SuccessHeader).println "\t +addDependenciesFromNativeScriptPlugins: " + getDepPlatformDir(dep) def aarFiles = fileTree(dir: getDepPlatformDir(dep), include: ["**/*.aar"]) def currentDirname = file(project.buildscript.sourceFile).getParentFile().getName() aarFiles.each { aarFile -> From 7c954ec9af1eb90e98950f97d3ae25f95a456c20 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Mon, 27 Jun 2022 15:45:46 +0200 Subject: [PATCH 3/6] chore: cleanup --- vendor/gradle-plugin/gradle.properties | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/vendor/gradle-plugin/gradle.properties b/vendor/gradle-plugin/gradle.properties index 84a8b08c9c..9e87ff2ebc 100644 --- a/vendor/gradle-plugin/gradle.properties +++ b/vendor/gradle-plugin/gradle.properties @@ -1,19 +1,4 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -#org.gradle.parallel=true - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. +# Nativescript CLI plugin build gradle properties org.gradle.jvmargs=-Xmx16384M android.enableJetifier=true From b9e7ec02e32095e5bb4def5bad68f16d11ea3e57 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Mon, 27 Jun 2022 15:45:59 +0200 Subject: [PATCH 4/6] fix: refactor to be compatible with older runtimers --- vendor/gradle-plugin/build.gradle | 66 ++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index c2beeb220d..47ed3a30b6 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -7,7 +7,71 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' +def loadPropertyFile = { path -> + try { + if(project.hasProperty("loadedProperties_${path}")) { + logger.info "\t + gradle properties already loaded. SKIPPING" + } else { + logger.info "\t + trying to load gradle properties from \"$path\"" + + Properties properties = new Properties() + properties.load(new FileInputStream("$path")) + properties.each { prop -> + logger.info "\t + [$path] setting ${prop.key} = ${prop.value}" + project.ext.set(prop.key, prop.value) + } + project.ext.set("loadedProperties_${path}", true) + + outLogger.withStyle(Style.SuccessHeader).println "\t + loaded gradle properties from \"$path\"" + } + } catch(Exception ex) { + logger.warn "\t + failed to load gradle properties from \"$path\". Error is: ${ex.getMessage()}" + } +} + buildscript { + def GRADLE_PROPERTIES_FILENAME = "gradle.properties" + + def getFile = { dir, filename -> + File file = new File("$dir$File.separator$filename") + file?.exists() ? file : null + } + + def getPropertyFile = { dir -> + return getFile(dir, GRADLE_PROPERTIES_FILENAME) + } + def getUserProperties = { dir -> + def file = getPropertyFile(dir) + if (!file) { + return null + } + + Properties properties = new Properties() + properties.load(file.newInputStream()) + + return properties + } + def loadPropertyFile = { path -> + try { + if(project.hasProperty("loadedProperties_${path}")) { + logger.info "\t + gradle properties already loaded. SKIPPING" + } else { + logger.info "\t + trying to load gradle properties from \"$path\"" + + Properties properties = new Properties() + properties.load(new FileInputStream("$path")) + properties.each { prop -> + logger.info "\t + [$path] setting ${prop.key} = ${prop.value}" + project.ext.set(prop.key, prop.value) + } + project.ext.set("loadedProperties_${path}", true) + + outLogger.withStyle(Style.SuccessHeader).println "\t + loaded gradle properties from \"$path\"" + } + } catch(Exception ex) { + logger.warn "\t + failed to load gradle properties from \"$path\". Error is: ${ex.getMessage()}" + } + } def initialize = { -> // set up our logger project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") @@ -19,8 +83,6 @@ buildscript { project.ext.PLUGIN_NAME = "{{pluginName}}" def userDir = "$USER_PROJECT_ROOT" - apply from: "$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle-helpers/user_properties_reader.gradle" - apply from: "$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle-helpers/paths.gradle" rootProject.ext.userDefinedGradleProperties = getUserProperties("${getAppResourcesPath(USER_PROJECT_ROOT)}/Android") loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle.properties") From 048f63e3eba92a6caf3d9af9b4b710717bfd0df8 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Fri, 1 Jul 2022 11:07:33 +0200 Subject: [PATCH 5/6] fix: vendor build.gradle fix --- vendor/gradle-plugin/build.gradle | 80 +++++++++++++++++++------------ 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 47ed3a30b6..12429d7c11 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -72,6 +72,55 @@ buildscript { logger.warn "\t + failed to load gradle properties from \"$path\". Error is: ${ex.getMessage()}" } } + def getAppResourcesPath = { -> + def relativePathToAppResources + def absolutePathToAppResources + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") + def nsConfig + + if (nsConfigFile.exists()) { + nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + } + + if (project.hasProperty("appResourcesPath")) { + // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources + // the path could be relative or absolute - either case will work + relativePathToAppResources = appResourcesPath + absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() + } else if (nsConfig != null && nsConfig.appResourcesPath != null) { + relativePathToAppResources = nsConfig.appResourcesPath + absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() + } else { + absolutePathToAppResources = "${getAppPath()}/App_Resources" + } + + project.ext.appResourcesPath = absolutePathToAppResources + + return absolutePathToAppResources + } + + + def getAppPath = { -> + def relativePathToApp = "app" + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") + def nsConfig + + if (nsConfigFile.exists()) { + nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + } + + if (project.hasProperty("appPath")) { + // when appPath is passed through -PappPath=/path/to/app + // the path could be relative or absolute - either case will work + relativePathToApp = appPath + } else if (nsConfig != null && nsConfig.appPath != null) { + relativePathToApp = nsConfig.appPath + } + + project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath() + + return project.ext.appPath + } def initialize = { -> // set up our logger project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") @@ -83,7 +132,7 @@ buildscript { project.ext.PLUGIN_NAME = "{{pluginName}}" def userDir = "$USER_PROJECT_ROOT" - rootProject.ext.userDefinedGradleProperties = getUserProperties("${getAppResourcesPath(USER_PROJECT_ROOT)}/Android") + rootProject.ext.userDefinedGradleProperties = getUserProperties("${getAppResourcesPath()}/Android") loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/gradle.properties") loadPropertyFile("$USER_PROJECT_ROOT/${project.ext.PLATFORMS_ANDROID}/additional_gradle.properties") @@ -160,35 +209,6 @@ buildscript { return project.ext.appPath } - - project.ext.getAppResourcesPath = { -> - def relativePathToAppResources - def absolutePathToAppResources - def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") - def nsConfig - - if (nsConfigFile.exists()) { - nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) - } - - if (project.hasProperty("appResourcesPath")) { - // when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources - // the path could be relative or absolute - either case will work - relativePathToAppResources = appResourcesPath - absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() - } else if (nsConfig != null && nsConfig.appResourcesPath != null) { - relativePathToAppResources = nsConfig.appResourcesPath - absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath() - } else { - absolutePathToAppResources = "${getAppPath()}/App_Resources" - } - - project.ext.appResourcesPath = absolutePathToAppResources - - return absolutePathToAppResources - } - - } def applyBuildScriptConfigurations = { -> def absolutePathToAppResources = getAppResourcesPath() From c63fc18b22b2cb724af6b47c2a05d5c2204c520e Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Sat, 16 Jul 2022 14:12:01 +0200 Subject: [PATCH 6/6] fix: gradle methods order fix --- vendor/gradle-plugin/build.gradle | 48 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 12429d7c11..e8436b0aa6 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -72,6 +72,27 @@ buildscript { logger.warn "\t + failed to load gradle properties from \"$path\". Error is: ${ex.getMessage()}" } } + def getAppPath = { -> + def relativePathToApp = "app" + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") + def nsConfig + + if (nsConfigFile.exists()) { + nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) + } + + if (project.hasProperty("appPath")) { + // when appPath is passed through -PappPath=/path/to/app + // the path could be relative or absolute - either case will work + relativePathToApp = appPath + } else if (nsConfig != null && nsConfig.appPath != null) { + relativePathToApp = nsConfig.appPath + } + + project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath() + + return project.ext.appPath + } def getAppResourcesPath = { -> def relativePathToAppResources def absolutePathToAppResources @@ -99,28 +120,6 @@ buildscript { return absolutePathToAppResources } - - def getAppPath = { -> - def relativePathToApp = "app" - def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") - def nsConfig - - if (nsConfigFile.exists()) { - nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) - } - - if (project.hasProperty("appPath")) { - // when appPath is passed through -PappPath=/path/to/app - // the path could be relative or absolute - either case will work - relativePathToApp = appPath - } else if (nsConfig != null && nsConfig.appPath != null) { - relativePathToApp = nsConfig.appPath - } - - project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath() - - return project.ext.appPath - } def initialize = { -> // set up our logger project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") @@ -295,6 +294,7 @@ android { nativescriptDependencies.each { dep -> def includeGradlePath = "${getDepPlatformDir(dep)}/include.gradle" if (file(includeGradlePath).exists()) { + outLogger.withStyle(Style.SuccessHeader).println "\t + applying plugin include.gradle from dependency ${includeGradlePath}" apply from: includeGradlePath } } @@ -310,6 +310,10 @@ android { versionCode 1 versionName "1.0" } + lintOptions { + checkReleaseBuilds false + abortOnError false + } }