Skip to content

Commit 8fbe761

Browse files
committed
use the correct build.gradle file
1 parent 52b3d0f commit 8fbe761

File tree

1 file changed

+73
-50
lines changed

1 file changed

+73
-50
lines changed

build/project-template-gradle/build.gradle

Lines changed: 73 additions & 50 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-
* -PrunSBGenerator //this flag will triger static binding generation
18+
* -PdontRunSbg=[true/false] (default false)
1919
*/
2020

2121
buildscript {
@@ -33,15 +33,19 @@ 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 = "configurations"
36+
def configurationsDir = "$projectDir/configurations"
3737
def createPluginConfigFile = false
3838
def configStage = "\n:config phase: "
3939
def nodeModulesDir = "../../node_modules/"
40-
def libDir = "../../lib/Android/"
41-
def pluginNames = new ArrayList<String>()
40+
def libDir = "$projectDir/../../lib/Android/"
41+
def flavorNames = new ArrayList<String>()
4242
def configDir = file(configurationsDir)
43-
def appResExists = false
44-
def appResourcesName = "NativescriptAppResources"
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")
4549

4650
def compiteCompileSdkVersion () {
4751
if(project.hasProperty("compileSdk")) {
@@ -66,7 +70,7 @@ def computeBuildToolsVersion() {
6670
return buildToolsVersion
6771
}
6872
else {
69-
return "22.0.1"
73+
return "23.0.1"
7074
}
7175
}
7276
project.ext.selectedBuildType = project.hasProperty("release") ? "release" : "debug"
@@ -102,7 +106,7 @@ android {
102106
}
103107

104108
sourceSets.main {
105-
jniLibs.srcDir "libs/jni"
109+
jniLibs.srcDir "$projectDir/libs/jni"
106110
}
107111

108112
signingConfigs {
@@ -136,7 +140,15 @@ android {
136140
def variantName = variant.name.capitalize()
137141
def compileSourcesTaskName = "compile${variantName}Sources"
138142
def compileSourcesTask = project.tasks.findByName(compileSourcesTaskName)
139-
compileSourcesTask.finalizedBy "buildMetadata"
143+
144+
def generateBuildConfigTask = variant.generateBuildConfig;
145+
generateBuildConfigTask.finalizedBy(collectAllJars)
146+
147+
if(!dontRunSbg) {
148+
collectAllJars.finalizedBy(setProperties)
149+
}
150+
151+
compileSourcesTask.finalizedBy(buildMetadata)
140152
}
141153
}
142154

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

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

163175
// take all jars within the node_modules dir
164176
compile fileTree(dir: nodeModulesDir, include: ["**/platforms/android/**/*.jar"], exclude: '**/.bin/**')
@@ -194,9 +206,8 @@ task pluginStructureCheck {
194206
}
195207
}
196208

197-
198209
def createIncludeFile (filePath, fileName, dimensionName) {
199-
println "\t+creating include.gradle file for: " + filePath + " flavor: " + fileName
210+
println "\t+creating include.gradle file for: " + filePath
200211
def defaultIncludeFile = new File(filePath, "include.gradle")
201212
defaultIncludeFile.write ""
202213
defaultIncludeFile << "android { \n"
@@ -258,10 +269,10 @@ task createDefaultIncludeFiles {
258269
}
259270
}
260271

261-
pluginNames.add('"' + dimensionName + '"')
272+
flavorNames.add('"' + dimensionName + '"')
262273

263274
if(!foundIncludeFile) {
264-
//createIncludeFile(fl.getAbsolutePath(), fileName, dimensionName)
275+
//createIncludeFile(fl.getAbsolutePath() ,fileName, dimensionName)
265276
createIncludeFile(fl.getAbsolutePath() , flavor, dimensionName)
266277
}
267278
}
@@ -279,7 +290,7 @@ task createPluginsConfigFile {
279290

280291
if(createPluginConfigFile) {
281292
println "\t+creating product flavors include.gradle file in $configurationsDir folder..."
282-
def flavors = pluginNames.join(",")
293+
def flavors = flavorNames.join(",")
283294

284295
flavorsFile << "android { \n"
285296
flavorsFile << "\tflavorDimensions " + flavors + "\n"
@@ -291,7 +302,7 @@ task createPluginsConfigFile {
291302
task pluginExtend {
292303
description "applies additional configuration"
293304

294-
def pathToAppGradle = "../../app/App_Resources/Android/app.gradle"
305+
def pathToAppGradle = "$projectDir/../../app/App_Resources/Android/app.gradle"
295306
def appGradle = file(pathToAppGradle)
296307
if(appGradle.exists()) {
297308
apply from: pathToAppGradle
@@ -323,13 +334,13 @@ task pluginExtend {
323334
task copyAarDependencies (type: Copy) {
324335
println "$configStage copyAarDependencies"
325336
from fileTree(dir: nodeModulesDir, include: ["**/*.aar"], exclude: '**/.bin/**').files
326-
into "libs/aar"
337+
into "$projectDir/libs/aar"
327338
}
328339

329340
task addAarDependencies << {
330341
println "$configStage addAarDependencies"
331342
// manually traverse all the locally copied AAR files and add them to the project compilation dependencies list
332-
FileTree tree = fileTree(dir: "libs/aar", include: ["**/*.aar"])
343+
FileTree tree = fileTree(dir: "$projectDir/libs/aar", include: ["**/*.aar"])
333344
tree.each { File file ->
334345
// remove the extension of the file (.aar)
335346
def length = file.name.length() - 4
@@ -345,11 +356,11 @@ task addAarDependencies << {
345356
////////////////////////////////////////////////////////////////////////////////////
346357

347358
task cleanLocalAarFiles(type: Delete) {
348-
delete fileTree(dir: "libs/aar", include: ["*.aar"])
359+
delete fileTree(dir: "$projectDir/libs/aar", include: ["*.aar"])
349360
}
350361

351362
task ensureMetadataOutDir {
352-
def outputDir = file("$rootDir/metadata/output/assets/metadata")
363+
def outputDir = file("$projectDir/metadata/output/assets/metadata")
353364
outputDir.mkdirs()
354365
}
355366

@@ -374,12 +385,35 @@ task collectAllJars {
374385
}
375386

376387
metadataParams.add("metadata-generator.jar")
377-
metadataParams.add("../metadata/output/assets/metadata")
388+
metadataParams.add("$projectDir/metadata/output/assets/metadata")
389+
def jars = new LinkedList<File>()
378390
for(def i = 0; i < allJarPaths.size(); i++) {
379391
metadataParams.add(allJarPaths.get(i));
392+
def f = new File(allJarPaths.get(i))
393+
if (f.getName().endsWith(".jar")) {
394+
jars.add(f)
395+
}
380396
}
397+
asbgProject.ext.jarFiles = jars
398+
}
399+
}
400+
401+
task buildMetadata (type: JavaExec) {
402+
description "builds metadata with provided jar dependencies"
403+
404+
inputs.files(allJarPaths)
405+
inputs.dir("$buildDir/intermediates/classes")
406+
407+
outputs.files("metadata/output/assets/metadata/treeNodeStream.dat", "metadata/output/assets/metadata/treeStringsStream.dat", "metadata/output/assets/metadata/treeValueStream.dat")
408+
409+
doFirst {
410+
workingDir "build-tools"
411+
412+
main "-jar"
381413

382-
def classesDir = "$rootDir/build/intermediates/classes"
414+
// get compiled classes to pass to metadata generator
415+
// these need to be called after the classes have compiled
416+
def classesDir = "$buildDir/intermediates/classes"
383417

384418
def classesSubDirs = new File(classesDir).listFiles()
385419

@@ -398,30 +432,14 @@ task collectAllJars {
398432
if (classesDirBuildType.exists()) {
399433
metadataParams.add(classesDirBuildType.getAbsolutePath())
400434
}
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"
417435

418436
args metadataParams.toArray()
419437
}
420438

421439
doLast {
422440
copy {
423-
from "metadata/output/assets/metadata"
424-
into "src/main/assets/metadata"
441+
from "$projectDir/metadata/output/assets/metadata"
442+
into "$projectDir/src/main/assets/metadata"
425443
}
426444

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

446464
exec {
447465
ignoreExitValue true
448-
workingDir "metadata/output"
466+
workingDir "$projectDir/metadata/output"
449467
commandLine removeCmdParams.toArray()
450468
}
451469

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

454472
exec {
455-
workingDir "metadata/output"
473+
workingDir "$projectDir/metadata/output"
456474
commandLine addCmdParams.toArray()
457475
}
458476
}
@@ -474,14 +492,20 @@ task deleteExplodedAarFolder (type: Delete) {
474492
////////////////////////////////////////////////////////////////////////////////////
475493
////////////////////////////// OPTIONAL TASKS //////////////////////////////////////
476494
////////////////////////////////////////////////////////////////////////////////////
477-
task runBindingGenerator(dependsOn: "ing:jar") {
478-
rootProject.jarsDir = allJarPaths
479-
}
480-
runBindingGenerator.dependsOn("bg:jar")
481-
482-
task rbg (dependsOn: "asbg:generatebindings")
483-
495+
task setProperties {
496+
project.ext.jarFiles = []
497+
doLast {
498+
def list = [];
499+
allJarPaths.each({f ->
500+
if(f.endsWith(".jar")) {
501+
list.add(f);
502+
}
503+
})
504+
project.jarFiles = list;
505+
}
506+
}
484507

508+
setProperties.finalizedBy("asbg:generateBindings")
485509

486510
////////////////////////////////////////////////////////////////////////////////////
487511
////////////////////////////// EXECUTION ORDER /////////////////////////////////////
@@ -518,4 +542,3 @@ task buildapk {
518542

519543
dependsOn deleteExplodedAarFolder
520544
}
521-

0 commit comments

Comments
 (0)