@@ -33,11 +33,15 @@ apply plugin: "com.android.application"
3333def isWinOs = System . properties[' os.name' ]. toLowerCase(). contains(' windows' )
3434def metadataParams = new LinkedList <String > ()
3535def allJarPaths = new LinkedList <String > ()
36+ def configurationsDir = " configurations"
3637def createPluginConfigFile = false
3738def configStage = " \n :config phase: "
3839def nodeModulesDir = " ../../node_modules/"
3940def libDir = " ../../lib/Android/"
4041def pluginNames = new ArrayList<String > ()
42+ def configDir = file(configurationsDir)
43+ def appResExists = false
44+ def appResourcesName = " NativescriptAppResources"
4145
4246def compiteCompileSdkVersion () {
4347 if (project. hasProperty(" compileSdk" )) {
@@ -174,6 +178,103 @@ dependencies {
174178// /////////////////////////// CONFIGURATION PHASE //////////////////////////////////
175179// //////////////////////////////////////////////////////////////////////////////////
176180
181+ task pluginStructureCheck {
182+ def ft = fileTree(dir : nodeModulesDir, include : [" **/platforms/android/**/*.*" ], exclude : ' **/.bin/**' )
183+ ft. files. each { f ->
184+ def fileName = f. getName();
185+ if (
186+ ! fileName. endsWith(" .aar" )
187+ &&
188+ ! fileName. equals(" include.gradle" )
189+ &&
190+ ! fileName. endsWith(" .jar" )
191+ ){
192+ println " WARNING: The file: " + f + " is depricated, you can read more about what will be the expected plugin structure here: https://www.nativescript.org/blog/migrating-n-android-plugins-from-version-1.7-to-2.0"
193+ }
194+ }
195+ }
196+
197+ def createIncludeFile (filePath , fileName , dimensionName ) {
198+ println " \t +creating include.gradle file for: " + filePath
199+ def defaultIncludeFile = new File (filePath, " include.gradle" )
200+ defaultIncludeFile. write " "
201+ defaultIncludeFile << " android { \n "
202+ defaultIncludeFile << " \t productFlavors {\n "
203+ defaultIncludeFile << ' \t\t "' + fileName + ' " {\n '
204+ defaultIncludeFile << ' \t\t\t dimension "' + dimensionName + ' "\n '
205+ defaultIncludeFile << " \t\t }\n "
206+ defaultIncludeFile << " \t }\n "
207+ defaultIncludeFile << " }"
208+ }
209+
210+ def sanatizeDimensionName (str ) {
211+ return str. replaceAll(/ \W / , " " )
212+ }
213+
214+ // make sure the include.gradle file, produced by the user, has only allowed characters in dimension attribute and remove any invalid characters if necessary
215+ def updateIncludeGradleFile (subFile , dimensionName ) {
216+ def igFile = new File (subFile. getAbsolutePath())
217+ def newContent = igFile. text. replaceAll(/ dimension\s +["'](.+?)["']/ ) { fullMatch , fDimension ->
218+ def newFg = sanatizeDimensionName(fDimension)
219+ dimensionName = newFg
220+ return " dimension \" $newFg \" "
221+ }
222+ igFile. text = newContent
223+
224+ return dimensionName
225+ }
226+
227+ task createDefaultIncludeFiles {
228+ description " creates default include.gradle files for added plugins IF NECESSARY"
229+ println " $configStage createDefaultIncludeFiles"
230+ def ft = file(configurationsDir)
231+
232+ ft. listFiles(). each { fl ->
233+
234+ if (fl. isDirectory()) {
235+ def fileName = fl. name
236+ def dimensionName = sanatizeDimensionName(fileName)
237+ createPluginConfigFile = true
238+ def foundIncludeFile = false
239+
240+ println " \t +found plugins: " + fileName
241+ fl. listFiles(). each { subFile ->
242+
243+ if (subFile. name == " include.gradle" ) {
244+ foundIncludeFile = true
245+ dimensionName = updateIncludeGradleFile(subFile, dimensionName)
246+ }
247+ }
248+
249+ pluginNames. add(' "' + dimensionName + ' "' )
250+
251+ if (! foundIncludeFile) {
252+ createIncludeFile(fl. getAbsolutePath() ,fileName, dimensionName)
253+ }
254+ }
255+ }
256+ }
257+
258+ task createPluginsConfigFile {
259+ description " creates product flavor config file based on what plugins are added"
260+
261+ if (configDir. exists()) {
262+ println " $configStage createPluginsConfigFile"
263+
264+ def flavorsFile = new File (" $configurationsDir /include.gradle" )
265+ flavorsFile. write " " // clear config file
266+
267+ if (createPluginConfigFile) {
268+ println " \t +creating product flavors include.gradle file in $configurationsDir folder..."
269+ def flavors = pluginNames. join(" ," )
270+
271+ flavorsFile << " android { \n "
272+ flavorsFile << " \t flavorDimensions " + flavors + " \n "
273+ flavorsFile << " }\n "
274+ }
275+ }
276+ }
277+
177278task pluginExtend {
178279 description " applies additional configuration"
179280
@@ -182,11 +283,15 @@ task pluginExtend {
182283 if (appGradle. exists()) {
183284 apply from : pathToAppGradle
184285 }
185-
186- def ft = fileTree(dir : nodeModulesDir, include : [" **/platforms/android/**/include.gradle" ])
187- ft. each { File igFile ->
188- println igFile
189- apply from : igFile
286+
287+ if (configDir. exists()) {
288+ println " $configStage pluginExtend"
289+ configDir. eachFileRecurse(groovy.io.FileType . FILES ) {
290+ if (it. name. equals(' include.gradle' )) {
291+ println " \t +applying configuration from: " + it
292+ apply from : it
293+ }
294+ }
190295 }
191296}
192297
0 commit comments