Skip to content

Commit 370cd86

Browse files
authored
Merge pull request #970 from NativeScript/pete/external-paths
chore(project-build-script): externalize app and appResources paths for other gradle scripts to use
2 parents 2e720f7 + cdef0d3 commit 370cd86

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

test-app/app/build.gradle

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,43 @@ def computeBuildToolsVersion = { ->
6767
}
6868

6969
project.ext.selectedBuildType = project.hasProperty("release") ? "release" : "debug"
70+
project.ext.appResourcesPath = ""
7071

7172
////////////////////////////////////////////////////////////////////////////////////
7273
///////////////////////////// CONFIGURATIONS ///////////////////////////////////////
7374
////////////////////////////////////////////////////////////////////////////////////
7475

75-
def getAppResourcesDirectory = { ->
76-
def defaultPathToAppResources = "$USER_PROJECT_ROOT/app/App_Resources"
77-
def pathToAppResources
76+
def getAppResourcesPath = { ->
77+
def relativePathToApp = "app"
78+
def relativePathToAppResources
79+
def absolutePathToAppResources
7880
def nsConfigFile = file("$USER_PROJECT_ROOT/nsconfig.json")
81+
def nsConfig
7982

8083
if (nsConfigFile.exists()) {
81-
def nsConfigJsonContent = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
84+
nsConfig = new JsonSlurper().parseText(nsConfigFile.getText("UTF-8"))
85+
}
8286

83-
if (nsConfigJsonContent.appResourcesPath != null) {
84-
pathToAppResources = java.nio.file.Paths.get(USER_PROJECT_ROOT).resolve(nsConfigJsonContent.appResourcesPath).toAbsolutePath()
85-
} else if (nsConfigJsonContent.appPath != null) {
86-
pathToAppResources = java.nio.file.Paths.get(USER_PROJECT_ROOT).resolve(nsConfigJsonContent.appPath).toAbsolutePath()
87-
}
87+
if(nsConfig != null && nsConfig.appPath != null){
88+
relativePathToApp = nsConfig.appPath
8889
}
8990

90-
return pathToAppResources != null ? pathToAppResources : defaultPathToAppResources
91-
}
91+
if(nsConfig != null && nsConfig.appResourcesPath != null ) {
92+
relativePathToAppResources = nsConfig.appResourcesPath
93+
} else {
94+
relativePathToAppResources = "$relativePathToApp/App_Resources"
95+
}
96+
97+
absolutePathToAppResources = java.nio.file.Paths.get(USER_PROJECT_ROOT).resolve(relativePathToAppResources).toAbsolutePath()
98+
99+
project.ext.appResourcesPath = absolutePathToAppResources
100+
101+
return absolutePathToAppResources
102+
};
92103

93104
def applyAppGradleConfiguration = { ->
94-
def appResourcesDir = getAppResourcesDirectory()
95-
def pathToAppGradle = "$appResourcesDir/Android/app.gradle"
105+
def appResourcesPath = getAppResourcesPath()
106+
def pathToAppGradle = "$appResourcesPath/Android/app.gradle"
96107
def appGradle = file(pathToAppGradle)
97108
if (appGradle.exists()) {
98109
println "\t + applying user-defined configuration from ${appGradle}"
@@ -170,8 +181,8 @@ repositories {
170181
pluginDependencies.add("libs/runtime-libs")
171182
}
172183

173-
def localAppResources = getAppResourcesDirectory()
174-
def localAppResourcesLibraries = "$localAppResources/Android/libs"
184+
def appResourcesPath = getAppResourcesPath()
185+
def localAppResourcesLibraries = "$appResourcesPath/Android/libs"
175186

176187
pluginDependencies.add(localAppResourcesLibraries)
177188

@@ -244,8 +255,8 @@ task addDependenciesFromNativeScriptPlugins {
244255
}
245256

246257
task addDependenciesFromAppResourcesLibraries {
247-
def appResources = getAppResourcesDirectory()
248-
def appResourcesLibraries = file("$appResources/Android/libs")
258+
def appResourcesPath = getAppResourcesPath()
259+
def appResourcesLibraries = file("$appResourcesPath/Android/libs")
249260
if (appResourcesLibraries.exists()) {
250261
def aarFiles = fileTree(dir: appResourcesLibraries, include: ["**/*.aar"])
251262
aarFiles.each { aarFile ->

0 commit comments

Comments
 (0)