Skip to content

Commit 52b3d0f

Browse files
committed
fixes #369 long paths on window
A possible temporary fix for the long paths on Windows builds when multiple {N} plugins are used.
1 parent fbc80d4 commit 52b3d0f

File tree

1 file changed

+61
-73
lines changed

1 file changed

+61
-73
lines changed

build/project-template-gradle/build.gradle

Lines changed: 61 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* -PsupportVersion=[support_version] (default (22.2.0)
1616
* -PcompileSdk=[compile_sdk_version] (default 22)
1717
*
18-
* -PdontRunSbg=[true/false] (default false)
18+
* -PrunSBGenerator //this flag will triger static binding generation
1919
*/
2020

2121
buildscript {
@@ -33,19 +33,15 @@ apply plugin: "com.android.application"
3333
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
3434
def metadataParams = new LinkedList <String> ()
3535
def allJarPaths = new LinkedList <String> ()
36-
def configurationsDir = "$projectDir/configurations"
36+
def configurationsDir = "configurations"
3737
def createPluginConfigFile = false
3838
def configStage = "\n:config phase: "
3939
def nodeModulesDir = "../../node_modules/"
40-
def libDir = "$projectDir/../../lib/Android/"
40+
def libDir = "../../lib/Android/"
4141
def pluginNames = new ArrayList<String>()
4242
def configDir = file(configurationsDir)
43-
44-
def dontRunSbg = project.hasProperty("dontRunSbg");
45-
46-
def asbgProject = project(":asbg")
47-
asbgProject.ext.outDir = new File("$projectDir", "src/main/java")
48-
asbgProject.ext.jsCodeDir = new File("$projectDir", "src/main/assets/app")
43+
def appResExists = false
44+
def appResourcesName = "NativescriptAppResources"
4945

5046
def compiteCompileSdkVersion () {
5147
if(project.hasProperty("compileSdk")) {
@@ -70,7 +66,7 @@ def computeBuildToolsVersion() {
7066
return buildToolsVersion
7167
}
7268
else {
73-
return "23.0.1"
69+
return "22.0.1"
7470
}
7571
}
7672
project.ext.selectedBuildType = project.hasProperty("release") ? "release" : "debug"
@@ -106,7 +102,7 @@ android {
106102
}
107103

108104
sourceSets.main {
109-
jniLibs.srcDir "$projectDir/libs/jni"
105+
jniLibs.srcDir "libs/jni"
110106
}
111107

112108
signingConfigs {
@@ -140,15 +136,7 @@ android {
140136
def variantName = variant.name.capitalize()
141137
def compileSourcesTaskName = "compile${variantName}Sources"
142138
def compileSourcesTask = project.tasks.findByName(compileSourcesTaskName)
143-
144-
def generateBuildConfigTask = variant.generateBuildConfig;
145-
generateBuildConfigTask.finalizedBy(collectAllJars)
146-
147-
if(!dontRunSbg) {
148-
collectAllJars.finalizedBy(setProperties)
149-
}
150-
151-
compileSourcesTask.finalizedBy(buildMetadata)
139+
compileSourcesTask.finalizedBy "buildMetadata"
152140
}
153141
}
154142

@@ -170,7 +158,7 @@ dependencies {
170158
compile "com.android.support:appcompat-v7:$suppotVer"
171159

172160
// take all jars within the libs dir
173-
compile fileTree(dir: "$projectDir/libs", include: ["**/*.jar"])
161+
compile fileTree(dir: "libs", include: ["**/*.jar"])
174162

175163
// take all jars within the node_modules dir
176164
compile fileTree(dir: nodeModulesDir, include: ["**/platforms/android/**/*.jar"], exclude: '**/.bin/**')
@@ -206,8 +194,9 @@ task pluginStructureCheck {
206194
}
207195
}
208196

197+
209198
def createIncludeFile (filePath, fileName, dimensionName) {
210-
println "\t+creating include.gradle file for: " + filePath
199+
println "\t+creating include.gradle file for: " + filePath + " flavor: " + fileName
211200
def defaultIncludeFile = new File(filePath, "include.gradle")
212201
defaultIncludeFile.write ""
213202
defaultIncludeFile << "android { \n"
@@ -224,18 +213,27 @@ def sanatizeDimensionName(str) {
224213
}
225214

226215
//make sure the include.gradle file, produced by the user, has only allowed characters in dimension attribute and remove any invalid characters if necessary
227-
def updateIncludeGradleFile(subFile, dimensionName) {
216+
def updateIncludeGradleFile(subFile, dimensionName, flavor) {
228217
def igFile = new File(subFile.getAbsolutePath())
229218
def newContent = igFile.text.replaceAll(/dimension\s+["'](.+?)["']/) { fullMatch, fDimension ->
230219
def newFg = sanatizeDimensionName(fDimension)
231220
dimensionName = newFg
232221
return "dimension \"$newFg\""
233222
}
234-
igFile.text = newContent
223+
224+
//println "Before patch: " + newContent
225+
226+
def finalContent = newContent.replace(dimensionName + "\" {", flavor + "\" {")
227+
228+
//println "Dimension: " + dimensionName + " final content: " + finalContent
229+
230+
igFile.text = finalContent
235231

236232
return dimensionName
237233
}
238234

235+
def flavorNumber = 0
236+
239237
task createDefaultIncludeFiles {
240238
description "creates default include.gradle files for added plugins IF NECESSARY"
241239
println "$configStage createDefaultIncludeFiles"
@@ -249,19 +247,22 @@ task createDefaultIncludeFiles {
249247
createPluginConfigFile = true
250248
def foundIncludeFile = false
251249

250+
def flavor = "F" + flavorNumber++
251+
252252
println "\t+found plugins: " + fileName
253253
fl.listFiles().each { subFile ->
254254

255255
if(subFile.name == "include.gradle") {
256256
foundIncludeFile = true
257-
dimensionName = updateIncludeGradleFile(subFile, dimensionName)
257+
dimensionName = updateIncludeGradleFile(subFile, dimensionName, flavor)
258258
}
259259
}
260260

261261
pluginNames.add('"' + dimensionName + '"')
262262

263263
if(!foundIncludeFile) {
264-
createIncludeFile(fl.getAbsolutePath() ,fileName, dimensionName)
264+
//createIncludeFile(fl.getAbsolutePath(), fileName, dimensionName)
265+
createIncludeFile(fl.getAbsolutePath() , flavor, dimensionName)
265266
}
266267
}
267268
}
@@ -290,7 +291,7 @@ task createPluginsConfigFile {
290291
task pluginExtend {
291292
description "applies additional configuration"
292293

293-
def pathToAppGradle = "$projectDir/../../app/App_Resources/Android/app.gradle"
294+
def pathToAppGradle = "../../app/App_Resources/Android/app.gradle"
294295
def appGradle = file(pathToAppGradle)
295296
if(appGradle.exists()) {
296297
apply from: pathToAppGradle
@@ -322,13 +323,13 @@ task pluginExtend {
322323
task copyAarDependencies (type: Copy) {
323324
println "$configStage copyAarDependencies"
324325
from fileTree(dir: nodeModulesDir, include: ["**/*.aar"], exclude: '**/.bin/**').files
325-
into "$projectDir/libs/aar"
326+
into "libs/aar"
326327
}
327328

328329
task addAarDependencies << {
329330
println "$configStage addAarDependencies"
330331
// manually traverse all the locally copied AAR files and add them to the project compilation dependencies list
331-
FileTree tree = fileTree(dir: "$projectDir/libs/aar", include: ["**/*.aar"])
332+
FileTree tree = fileTree(dir: "libs/aar", include: ["**/*.aar"])
332333
tree.each { File file ->
333334
// remove the extension of the file (.aar)
334335
def length = file.name.length() - 4
@@ -344,11 +345,11 @@ task addAarDependencies << {
344345
////////////////////////////////////////////////////////////////////////////////////
345346

346347
task cleanLocalAarFiles(type: Delete) {
347-
delete fileTree(dir: "$projectDir/libs/aar", include: ["*.aar"])
348+
delete fileTree(dir: "libs/aar", include: ["*.aar"])
348349
}
349350

350351
task ensureMetadataOutDir {
351-
def outputDir = file("$projectDir/metadata/output/assets/metadata")
352+
def outputDir = file("$rootDir/metadata/output/assets/metadata")
352353
outputDir.mkdirs()
353354
}
354355

@@ -373,35 +374,12 @@ task collectAllJars {
373374
}
374375

375376
metadataParams.add("metadata-generator.jar")
376-
metadataParams.add("$projectDir/metadata/output/assets/metadata")
377-
def jars = new LinkedList<File>()
377+
metadataParams.add("../metadata/output/assets/metadata")
378378
for(def i = 0; i < allJarPaths.size(); i++) {
379379
metadataParams.add(allJarPaths.get(i));
380-
def f = new File(allJarPaths.get(i))
381-
if (f.getName().endsWith(".jar")) {
382-
jars.add(f)
383-
}
384380
}
385-
asbgProject.ext.jarFiles = jars
386-
}
387-
}
388381

389-
task buildMetadata (type: JavaExec) {
390-
description "builds metadata with provided jar dependencies"
391-
392-
inputs.files(allJarPaths)
393-
inputs.dir("$buildDir/intermediates/classes")
394-
395-
outputs.files("metadata/output/assets/metadata/treeNodeStream.dat", "metadata/output/assets/metadata/treeStringsStream.dat", "metadata/output/assets/metadata/treeValueStream.dat")
396-
397-
doFirst {
398-
workingDir "build-tools"
399-
400-
main "-jar"
401-
402-
// get compiled classes to pass to metadata generator
403-
// these need to be called after the classes have compiled
404-
def classesDir = "$buildDir/intermediates/classes"
382+
def classesDir = "$rootDir/build/intermediates/classes"
405383

406384
def classesSubDirs = new File(classesDir).listFiles()
407385

@@ -420,14 +398,30 @@ task buildMetadata (type: JavaExec) {
420398
if (classesDirBuildType.exists()) {
421399
metadataParams.add(classesDirBuildType.getAbsolutePath())
422400
}
401+
}
402+
}
403+
404+
405+
task buildMetadata (type: JavaExec) {
406+
description "builds metadata with provided jar dependencies"
407+
408+
inputs.files(allJarPaths)
409+
inputs.dir("build/intermediates/classes")
410+
411+
outputs.files("metadata/output/assets/metadata/treeNodeStream.dat", "metadata/output/assets/metadata/treeStringsStream.dat", "metadata/output/assets/metadata/treeValueStream.dat")
412+
413+
doFirst {
414+
workingDir "build-tools"
415+
416+
main "-jar"
423417

424418
args metadataParams.toArray()
425419
}
426420

427421
doLast {
428422
copy {
429-
from "$projectDir/metadata/output/assets/metadata"
430-
into "$projectDir/src/main/assets/metadata"
423+
from "metadata/output/assets/metadata"
424+
into "src/main/assets/metadata"
431425
}
432426

433427
def files = new File("${buildDir}/intermediates/res").listFiles()
@@ -451,14 +445,14 @@ task buildMetadata (type: JavaExec) {
451445

452446
exec {
453447
ignoreExitValue true
454-
workingDir "$projectDir/metadata/output"
448+
workingDir "metadata/output"
455449
commandLine removeCmdParams.toArray()
456450
}
457451

458452
def addCmdParams = new ArrayList<String>([aaptCommand, "add", tmpAPKPath, "assets/metadata/treeNodeStream.dat", "assets/metadata/treeStringsStream.dat", "assets/metadata/treeValueStream.dat"])
459453

460454
exec {
461-
workingDir "$projectDir/metadata/output"
455+
workingDir "metadata/output"
462456
commandLine addCmdParams.toArray()
463457
}
464458
}
@@ -480,20 +474,14 @@ task deleteExplodedAarFolder (type: Delete) {
480474
////////////////////////////////////////////////////////////////////////////////////
481475
////////////////////////////// OPTIONAL TASKS //////////////////////////////////////
482476
////////////////////////////////////////////////////////////////////////////////////
483-
task setProperties {
484-
project.ext.jarFiles = []
485-
doLast {
486-
def list = [];
487-
allJarPaths.each({f ->
488-
if(f.endsWith(".jar")) {
489-
list.add(f);
490-
}
491-
})
492-
project.jarFiles = list;
493-
}
494-
}
477+
task runBindingGenerator(dependsOn: "ing:jar") {
478+
rootProject.jarsDir = allJarPaths
479+
}
480+
runBindingGenerator.dependsOn("bg:jar")
481+
482+
task rbg (dependsOn: "asbg:generatebindings")
483+
495484

496-
setProperties.finalizedBy("asbg:generateBindings")
497485

498486
////////////////////////////////////////////////////////////////////////////////////
499487
////////////////////////////// EXECUTION ORDER /////////////////////////////////////

0 commit comments

Comments
 (0)