From cf985b1f0e8fdd7facd5556a1f892e280906fe8e Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 15 Feb 2022 14:13:31 +0100 Subject: [PATCH 1/4] fix: correctly allow plugins build to detect before-plugins.gradle and other gradle scripts --- lib/services/android-plugin-build-service.ts | 4 +- vendor/gradle-plugin/build.gradle | 46 +++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/services/android-plugin-build-service.ts b/lib/services/android-plugin-build-service.ts index a277e7dc87..93f7926fca 100644 --- a/lib/services/android-plugin-build-service.ts +++ b/lib/services/android-plugin-build-service.ts @@ -17,7 +17,7 @@ import { IWatchIgnoreListService, } from "../declarations"; import { IPlatformsDataService } from "../definitions/platform"; -import { IProjectDataService } from "../definitions/project"; +import { IProjectData, IProjectDataService } from "../definitions/project"; import { IAndroidPluginBuildService, IPluginBuildOptions, @@ -49,6 +49,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { private $androidToolsInfo: IAndroidToolsInfo, private $logger: ILogger, private $packageManager: INodePackageManager, + private $projectData: IProjectData, private $projectDataService: IProjectDataService, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $errors: IErrors, @@ -723,6 +724,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { "assembleRelease", `-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`, `-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`, + `-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}` ]; if (this.$logger.getLevel() === "INFO") { diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 7fd52fc8f9..63dc99b052 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -1,6 +1,7 @@ import groovy.json.JsonSlurper import org.gradle.internal.logging.text.StyledTextOutputFactory import static org.gradle.internal.logging.text.StyledTextOutput.Style +import java.nio.file.Paths apply plugin: 'com.android.library' apply plugin: 'kotlin-android' @@ -25,31 +26,52 @@ buildscript { // Set up styled logger project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger") - // todo: pass appResourcesPath from CLI as a gradle arg - project.ext.getAppResourcesPath = { -> + project.ext.USER_PROJECT_ROOT = "$rootDir/../../.." + + project.ext.getAppPath = { -> def relativePathToApp = "app" - def relativePathToAppResources - def absolutePathToAppResources - def projectRoot = "$rootDir/../../.." - def nsConfigFile = file("$projectRoot/nsconfig.json") + def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json") def nsConfig if (nsConfigFile.exists()) { nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8")) } - if(nsConfig != null && nsConfig.appPath != null){ + 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 } - if(nsConfig != null && nsConfig.appResourcesPath != null ) { + project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath() + + 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 { - relativePathToAppResources = "$relativePathToApp/App_Resources" + absolutePathToAppResources = "${getAppPath()}/App_Resources" } - absolutePathToAppResources = java.nio.file.Paths.get(projectRoot).resolve(relativePathToAppResources).toAbsolutePath() - project.ext.appResourcesPath = absolutePathToAppResources return absolutePathToAppResources @@ -104,6 +126,7 @@ android { versionCode 1 versionName "1.0" } + println "computeCompileSdkVersion2() ${computeCompileSdkVersion()} ${computeandroidxVersion()}" } @@ -112,6 +135,7 @@ def applyBeforePluginGradleConfiguration() { def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle" def beforePluginGradle = file(pathToBeforePluginGradle) if (beforePluginGradle.exists()) { + println "applyBeforePluginGradleConfiguration" outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined configuration from ${beforePluginGradle}" apply from: pathToBeforePluginGradle } From ec3d8a557a578a0b02e26ee1d728ab0eed3e47d6 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 15 Feb 2022 14:22:20 +0100 Subject: [PATCH 2/4] chore: cleanup logs --- vendor/gradle-plugin/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 63dc99b052..b7f03c8ce7 100644 --- a/vendor/gradle-plugin/build.gradle +++ b/vendor/gradle-plugin/build.gradle @@ -126,7 +126,6 @@ android { versionCode 1 versionName "1.0" } - println "computeCompileSdkVersion2() ${computeCompileSdkVersion()} ${computeandroidxVersion()}" } @@ -135,7 +134,6 @@ def applyBeforePluginGradleConfiguration() { def pathToBeforePluginGradle = "$appResourcesPath/Android/before-plugins.gradle" def beforePluginGradle = file(pathToBeforePluginGradle) if (beforePluginGradle.exists()) { - println "applyBeforePluginGradleConfiguration" outLogger.withStyle(Style.SuccessHeader).println "\t ~ applying user-defined configuration from ${beforePluginGradle}" apply from: pathToBeforePluginGradle } From c85ec915063ae3b2cc4466c537af247d28842510 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Tue, 15 Feb 2022 14:47:01 +0100 Subject: [PATCH 3/4] chore: also pass `appPath` to plugin gradle build --- lib/services/android-plugin-build-service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/services/android-plugin-build-service.ts b/lib/services/android-plugin-build-service.ts index 93f7926fca..0f28d9f5ba 100644 --- a/lib/services/android-plugin-build-service.ts +++ b/lib/services/android-plugin-build-service.ts @@ -724,6 +724,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { "assembleRelease", `-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`, `-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`, + `-PappPath=${this.$projectData.getAppDirectoryPath()}`, `-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}` ]; From 2f6ff7cd84665f44ae996d4f663f9ebe94f93b5d Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Tue, 15 Feb 2022 14:58:11 +0100 Subject: [PATCH 4/4] test: fix tests --- test/services/android-plugin-build-service.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/services/android-plugin-build-service.ts b/test/services/android-plugin-build-service.ts index 9797602906..58e124750f 100644 --- a/test/services/android-plugin-build-service.ts +++ b/test/services/android-plugin-build-service.ts @@ -88,6 +88,7 @@ describe("androidPluginBuildService", () => { }, }); testInjector.register("packageManager", setupNpm(options)); + testInjector.register("projectData", stubs.ProjectDataStub); testInjector.register("filesHashService", { generateHashes: async ( files: string[] @@ -110,6 +111,10 @@ describe("androidPluginBuildService", () => { androidBuildPluginService = testInjector.resolve( AndroidPluginBuildService ); + + // initialize dummy projectData + const projectData = testInjector.resolve("projectData"); + projectData.initializeProjectData("test-project"); } function setupNpm(options: {