Skip to content

Commit 3b42042

Browse files
authored
fix: correctly allow plugins build to detect before-plugins.gradle (#5631)
1 parent 8446795 commit 3b42042

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

lib/services/android-plugin-build-service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
IWatchIgnoreListService,
1818
} from "../declarations";
1919
import { IPlatformsDataService } from "../definitions/platform";
20-
import { IProjectDataService } from "../definitions/project";
20+
import { IProjectData, IProjectDataService } from "../definitions/project";
2121
import {
2222
IAndroidPluginBuildService,
2323
IPluginBuildOptions,
@@ -49,6 +49,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
4949
private $androidToolsInfo: IAndroidToolsInfo,
5050
private $logger: ILogger,
5151
private $packageManager: INodePackageManager,
52+
private $projectData: IProjectData,
5253
private $projectDataService: IProjectDataService,
5354
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
5455
private $errors: IErrors,
@@ -727,6 +728,8 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
727728
"assembleRelease",
728729
`-PcompileSdk=android-${pluginBuildSettings.androidToolsInfo.compileSdkVersion}`,
729730
`-PbuildToolsVersion=${pluginBuildSettings.androidToolsInfo.buildToolsVersion}`,
731+
`-PappPath=${this.$projectData.getAppDirectoryPath()}`,
732+
`-PappResourcesPath=${this.$projectData.getAppResourcesDirectoryPath()}`
730733
];
731734
if (pluginBuildSettings.gradleArgs) {
732735
localArgs.push(pluginBuildSettings.gradleArgs);

test/services/android-plugin-build-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("androidPluginBuildService", () => {
8888
},
8989
});
9090
testInjector.register("packageManager", setupNpm(options));
91+
testInjector.register("projectData", stubs.ProjectDataStub);
9192
testInjector.register("filesHashService", <IFilesHashService>{
9293
generateHashes: async (
9394
files: string[]
@@ -110,6 +111,10 @@ describe("androidPluginBuildService", () => {
110111
androidBuildPluginService = testInjector.resolve<AndroidPluginBuildService>(
111112
AndroidPluginBuildService
112113
);
114+
115+
// initialize dummy projectData
116+
const projectData = testInjector.resolve("projectData");
117+
projectData.initializeProjectData("test-project");
113118
}
114119

115120
function setupNpm(options: {

vendor/gradle-plugin/build.gradle

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import groovy.json.JsonSlurper
22
import org.gradle.internal.logging.text.StyledTextOutputFactory
33
import static org.gradle.internal.logging.text.StyledTextOutput.Style
4+
import java.nio.file.Paths
45

56
apply plugin: 'com.android.library'
67
apply plugin: 'kotlin-android'
@@ -25,31 +26,52 @@ buildscript {
2526
// Set up styled logger
2627
project.ext.outLogger = services.get(StyledTextOutputFactory).create("colouredOutputLogger")
2728

28-
// todo: pass appResourcesPath from CLI as a gradle arg
29-
project.ext.getAppResourcesPath = { ->
29+
project.ext.USER_PROJECT_ROOT = "$rootDir/../../.."
30+
31+
project.ext.getAppPath = { ->
3032
def relativePathToApp = "app"
31-
def relativePathToAppResources
32-
def absolutePathToAppResources
33-
def projectRoot = "$rootDir/../../.."
34-
def nsConfigFile = file("$projectRoot/nsconfig.json")
33+
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
3534
def nsConfig
3635

3736
if (nsConfigFile.exists()) {
3837
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
3938
}
4039

41-
if(nsConfig != null && nsConfig.appPath != null){
40+
if (project.hasProperty("appPath")) {
41+
// when appPath is passed through -PappPath=/path/to/app
42+
// the path could be relative or absolute - either case will work
43+
relativePathToApp = appPath
44+
} else if (nsConfig != null && nsConfig.appPath != null) {
4245
relativePathToApp = nsConfig.appPath
4346
}
4447

45-
if(nsConfig != null && nsConfig.appResourcesPath != null ) {
48+
project.ext.appPath = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToApp).toAbsolutePath()
49+
50+
return project.ext.appPath
51+
}
52+
53+
project.ext.getAppResourcesPath = { ->
54+
def relativePathToAppResources
55+
def absolutePathToAppResources
56+
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
57+
def nsConfig
58+
59+
if (nsConfigFile.exists()) {
60+
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
61+
}
62+
63+
if (project.hasProperty("appResourcesPath")) {
64+
// when appResourcesPath is passed through -PappResourcesPath=/path/to/App_Resources
65+
// the path could be relative or absolute - either case will work
66+
relativePathToAppResources = appResourcesPath
67+
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
68+
} else if (nsConfig != null && nsConfig.appResourcesPath != null) {
4669
relativePathToAppResources = nsConfig.appResourcesPath
70+
absolutePathToAppResources = Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
4771
} else {
48-
relativePathToAppResources = "$relativePathToApp/App_Resources"
72+
absolutePathToAppResources = "${getAppPath()}/App_Resources"
4973
}
5074

51-
absolutePathToAppResources = java.nio.file.Paths.get(projectRoot).resolve(relativePathToAppResources).toAbsolutePath()
52-
5375
project.ext.appResourcesPath = absolutePathToAppResources
5476

5577
return absolutePathToAppResources

0 commit comments

Comments
 (0)