Skip to content

fix: correctly allow plugins build to detect before-plugins.gradle #5631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions test/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe("androidPluginBuildService", () => {
},
});
testInjector.register("packageManager", setupNpm(options));
testInjector.register("projectData", stubs.ProjectDataStub);
testInjector.register("filesHashService", <IFilesHashService>{
generateHashes: async (
files: string[]
Expand All @@ -110,6 +111,10 @@ describe("androidPluginBuildService", () => {
androidBuildPluginService = testInjector.resolve<AndroidPluginBuildService>(
AndroidPluginBuildService
);

// initialize dummy projectData
const projectData = testInjector.resolve("projectData");
projectData.initializeProjectData("test-project");
}

function setupNpm(options: {
Expand Down
44 changes: 33 additions & 11 deletions vendor/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down