From 24e77aaa8b77be15036d453c7aa863389ba33998 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Tue, 24 Apr 2018 17:58:31 +0300 Subject: [PATCH 1/2] feat(build.gradle): take applicationId from package.json fix(build.gradle): warning for different indentifiers not shown --- test-app/app/build.gradle | 65 ++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index bc54e7088..f910b93a9 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -127,6 +127,36 @@ def applyPluginGradleConfigurations = { -> } } +def getAppIdentifier = { packageJsonMap -> + def appIdentifier = ""; + if (packageJsonMap) { + appIdentifier = packageJsonMap.nativescript.id; + if (!(appIdentifier instanceof String)) { + appIdentifier = appIdentifier.android; + } + } + + return appIdentifier; +} + +def setAppIdentifier = { -> + println "\t + setting applicationId"; + File packageJsonFile = new File("$rootDir/../../package.json"); + + if (packageJsonFile.exists()) { + def content = packageJsonFile.getText("UTF-8"); + def jsonSlurper = new JsonSlurper(); + def packageJsonMap = jsonSlurper.parseText(content); + def appIdentifier = getAppIdentifier(packageJsonMap); + + if (appIdentifier) { + project.ext.nsApplicationIdentifier = appIdentifier; + android.defaultConfig.applicationId = appIdentifier; + } + } +} + + android { compileSdkVersion computeCompileSdkVersion() buildToolsVersion computeBuildToolsVersion() @@ -169,6 +199,7 @@ android { } } + setAppIdentifier() applyAppGradleConfiguration() applyPluginGradleConfigurations() } @@ -298,7 +329,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask -> currentTask.finalizedBy(ensureMetadataOutDir) ensureMetadataOutDir.finalizedBy(buildMetadata) } - if (currentTask =~ /assemble.+Debug/ || currentTask =~ /assemble.+Release/) { + if (currentTask =~ /assemble.*Debug/ || currentTask =~ /assemble.*Release/) { currentTask.finalizedBy("validateAppIdMatch") } }) @@ -511,23 +542,21 @@ copyTypings.onlyIf { generateTypescriptDefinitions.didWork } generateTypescriptDefinitions.finalizedBy(copyTypings) task validateAppIdMatch { - doLast { - def packageJsonFile = new File("$USER_PROJECT_ROOT/$PACKAGE_JSON") - def lineSeparator = System.getProperty("line.separator") - - if (packageJsonFile.exists() && !project.hasProperty("release")) { - String content = packageJsonFile.getText("UTF-8") - def jsonSlurper = new JsonSlurper() - def packageJsonMap = jsonSlurper.parseText(content) - - if (packageJsonMap.nativescript.id != android.defaultConfig.applicationId) { - def errorMessage = "${lineSeparator}WARNING: The Application identifier is different from the one inside $PACKAGE_JSON file.$lineSeparator" + - "NativeScript CLI might not work properly.$lineSeparator" + - "Update the application identifier in $PACKAGE_JSON and app.gradle so that they match." - logger.error(errorMessage) - } - } - } + doLast { + def lineSeparator = System.getProperty("line.separator") + + if (project.hasProperty("nsApplicationIdentifier") && !project.hasProperty("release")) { + if(project.nsApplicationIdentifier != android.defaultConfig.applicationId) { + def errorMessage = "${lineSeparator}WARNING: The Application identifier is different from the one inside \"package.json\" file.$lineSeparator" + + "NativeScript CLI might not work properly.$lineSeparator" + + "Remove applicationId from app.gradle and update the \"nativescript.id\" in package.json.$lineSeparator" + + "Actual: ${android.defaultConfig.applicationId}$lineSeparator" + + "Expected(from \"package.json\"): ${project.nsApplicationIdentifier}$lineSeparator"; + + logger.error(errorMessage) + } + } + } } //////////////////////////////////////////////////////////////////////////////////// From 68ce0e903e977bd1292a43e13ef2c842227ade9c Mon Sep 17 00:00:00 2001 From: Vasil Trifonov Date: Thu, 10 May 2018 15:08:29 +0300 Subject: [PATCH 2/2] added check for packageJsonMap.nativescript --- test-app/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index 76b2613a2..ae9cc3954 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -129,7 +129,7 @@ def applyPluginGradleConfigurations = { -> def getAppIdentifier = { packageJsonMap -> def appIdentifier = ""; - if (packageJsonMap) { + if (packageJsonMap && packageJsonMap.nativescript) { appIdentifier = packageJsonMap.nativescript.id; if (!(appIdentifier instanceof String)) { appIdentifier = appIdentifier.android;