diff --git a/lib/services/android-plugin-build-service.ts b/lib/services/android-plugin-build-service.ts index 3ef3a2c3b8..03fc61d512 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, @@ -727,6 +728,8 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { "assembleRelease", `-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`, `-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`, + `-PappPath=${this.$projectData.getAppDirectoryPath()}`, + `-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}` ]; if (pluginBuildSettings.gradleArgs) { localArgs.push(pluginBuildSettings.gradleArgs); 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: { diff --git a/vendor/gradle-plugin/build.gradle b/vendor/gradle-plugin/build.gradle index 7fd52fc8f9..b7f03c8ce7 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