Skip to content

Commit 81be198

Browse files
authored
Merge pull request #848 from NativeScript/kddimitrov/application-id-taken-from-packagejson
Take applicationId from package.json
2 parents 397f675 + 3b54239 commit 81be198

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

test-app/app/build.gradle

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ def applyPluginGradleConfigurations = { ->
127127
}
128128
}
129129

130+
def getAppIdentifier = { packageJsonMap ->
131+
def appIdentifier = "";
132+
if (packageJsonMap && packageJsonMap.nativescript) {
133+
appIdentifier = packageJsonMap.nativescript.id;
134+
if (!(appIdentifier instanceof String)) {
135+
appIdentifier = appIdentifier.android;
136+
}
137+
}
138+
139+
return appIdentifier;
140+
}
141+
142+
def setAppIdentifier = { ->
143+
println "\t + setting applicationId";
144+
File packageJsonFile = new File("$rootDir/../../package.json");
145+
146+
if (packageJsonFile.exists()) {
147+
def content = packageJsonFile.getText("UTF-8");
148+
def jsonSlurper = new JsonSlurper();
149+
def packageJsonMap = jsonSlurper.parseText(content);
150+
def appIdentifier = getAppIdentifier(packageJsonMap);
151+
152+
if (appIdentifier) {
153+
project.ext.nsApplicationIdentifier = appIdentifier;
154+
android.defaultConfig.applicationId = appIdentifier;
155+
}
156+
}
157+
}
158+
159+
130160
android {
131161
compileSdkVersion computeCompileSdkVersion()
132162
buildToolsVersion computeBuildToolsVersion()
@@ -169,6 +199,7 @@ android {
169199
}
170200
}
171201

202+
setAppIdentifier()
172203
applyAppGradleConfiguration()
173204
applyPluginGradleConfigurations()
174205
}
@@ -307,7 +338,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
307338
currentTask.finalizedBy(ensureMetadataOutDir)
308339
ensureMetadataOutDir.finalizedBy(buildMetadata)
309340
}
310-
if (currentTask =~ /assemble.+Debug/ || currentTask =~ /assemble.+Release/) {
341+
if (currentTask =~ /assemble.*Debug/ || currentTask =~ /assemble.*Release/) {
311342
currentTask.finalizedBy("validateAppIdMatch")
312343
}
313344
})
@@ -520,23 +551,21 @@ copyTypings.onlyIf { generateTypescriptDefinitions.didWork }
520551
generateTypescriptDefinitions.finalizedBy(copyTypings)
521552

522553
task validateAppIdMatch {
523-
doLast {
524-
def packageJsonFile = new File("$USER_PROJECT_ROOT/$PACKAGE_JSON")
525-
def lineSeparator = System.getProperty("line.separator")
526-
527-
if (packageJsonFile.exists() && !project.hasProperty("release")) {
528-
String content = packageJsonFile.getText("UTF-8")
529-
def jsonSlurper = new JsonSlurper()
530-
def packageJsonMap = jsonSlurper.parseText(content)
531-
532-
if (packageJsonMap.nativescript.id != android.defaultConfig.applicationId) {
533-
def errorMessage = "${lineSeparator}WARNING: The Application identifier is different from the one inside $PACKAGE_JSON file.$lineSeparator" +
534-
"NativeScript CLI might not work properly.$lineSeparator" +
535-
"Update the application identifier in $PACKAGE_JSON and app.gradle so that they match."
536-
logger.error(errorMessage)
537-
}
538-
}
539-
}
554+
doLast {
555+
def lineSeparator = System.getProperty("line.separator")
556+
557+
if (project.hasProperty("nsApplicationIdentifier") && !project.hasProperty("release")) {
558+
if(project.nsApplicationIdentifier != android.defaultConfig.applicationId) {
559+
def errorMessage = "${lineSeparator}WARNING: The Application identifier is different from the one inside \"package.json\" file.$lineSeparator" +
560+
"NativeScript CLI might not work properly.$lineSeparator" +
561+
"Remove applicationId from app.gradle and update the \"nativescript.id\" in package.json.$lineSeparator" +
562+
"Actual: ${android.defaultConfig.applicationId}$lineSeparator" +
563+
"Expected(from \"package.json\"): ${project.nsApplicationIdentifier}$lineSeparator";
564+
565+
logger.error(errorMessage)
566+
}
567+
}
568+
}
540569
}
541570

542571
////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)