|
@@ -1,97 +0,0 @@
|
1
|
|
-import org.apache.tools.ant.taskdefs.condition.Os
|
2
|
|
-
|
3
|
|
-def config = project.hasProperty("react") ? project.react : [];
|
4
|
|
-
|
5
|
|
-def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
|
6
|
|
-def entryFile = config.entryFile ?: "index.android.js"
|
7
|
|
-
|
8
|
|
-// because elvis operator
|
9
|
|
-def elvisFile(thing) {
|
10
|
|
- return thing ? file(thing) : null;
|
11
|
|
-}
|
12
|
|
-
|
13
|
|
-def reactRoot = elvisFile(config.root) ?: file("../../")
|
14
|
|
-def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
|
15
|
|
-
|
16
|
|
-void runBefore(String dependentTaskName, Task task) {
|
17
|
|
- Task dependentTask = tasks.findByPath(dependentTaskName);
|
18
|
|
- if (dependentTask != null) {
|
19
|
|
- dependentTask.dependsOn task
|
20
|
|
- }
|
21
|
|
-}
|
22
|
|
-
|
23
|
|
-gradle.projectsEvaluated {
|
24
|
|
- // Grab all build types and product flavors
|
25
|
|
- def buildTypes = android.buildTypes.collect { type -> type.name }
|
26
|
|
- def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
|
27
|
|
-
|
28
|
|
- // When no product flavors defined, use empty
|
29
|
|
- if (!productFlavors) productFlavors.add('')
|
30
|
|
-
|
31
|
|
- productFlavors.each { productFlavorName ->
|
32
|
|
- buildTypes.each { buildTypeName ->
|
33
|
|
- // Create variant and target names
|
34
|
|
- def targetName = "${productFlavorName.capitalize()}${buildTypeName.capitalize()}"
|
35
|
|
- def targetPath = productFlavorName ?
|
36
|
|
- "${productFlavorName}/${buildTypeName}" :
|
37
|
|
- "${buildTypeName}"
|
38
|
|
-
|
39
|
|
- // React js bundle directories
|
40
|
|
- def jsBundleDirConfigName = "jsBundleDir${targetName}"
|
41
|
|
- def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
|
42
|
|
- file("$buildDir/intermediates/assets/${targetPath}")
|
43
|
|
-
|
44
|
|
- def resourcesDirConfigName = "resourcesDir${targetName}"
|
45
|
|
- def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
|
46
|
|
- file("$buildDir/intermediates/res/merged/${targetPath}")
|
47
|
|
- def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
|
48
|
|
-
|
49
|
|
- // Bundle task name for variant
|
50
|
|
- def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets"
|
51
|
|
-
|
52
|
|
- def currentBundleTask = tasks.create(
|
53
|
|
- name: bundleJsAndAssetsTaskName,
|
54
|
|
- type: Exec) {
|
55
|
|
- group = "react"
|
56
|
|
- description = "bundle JS and assets for ${targetName}."
|
57
|
|
-
|
58
|
|
- // Create dirs if they are not there (e.g. the "clean" task just ran)
|
59
|
|
- doFirst {
|
60
|
|
- jsBundleDir.mkdirs()
|
61
|
|
- resourcesDir.mkdirs()
|
62
|
|
- }
|
63
|
|
-
|
64
|
|
- // Set up inputs and outputs so gradle can cache the result
|
65
|
|
- inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
|
66
|
|
- outputs.dir jsBundleDir
|
67
|
|
- outputs.dir resourcesDir
|
68
|
|
-
|
69
|
|
- // Set up the call to the react-native cli
|
70
|
|
- workingDir reactRoot
|
71
|
|
-
|
72
|
|
- // Set up dev mode
|
73
|
|
- def devEnabled = !targetName.toLowerCase().contains("release")
|
74
|
|
- if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
75
|
|
- commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
|
76
|
|
- "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
|
77
|
|
- } else {
|
78
|
|
- commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
|
79
|
|
- "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
|
80
|
|
- }
|
81
|
|
-
|
82
|
|
- enabled config."bundleIn${targetName}" ||
|
83
|
|
- config."bundleIn${buildTypeName.capitalize()}" ?:
|
84
|
|
- targetName.toLowerCase().contains("release")
|
85
|
|
- }
|
86
|
|
-
|
87
|
|
- // Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process
|
88
|
|
- currentBundleTask.dependsOn("merge${targetName}Resources")
|
89
|
|
- currentBundleTask.dependsOn("merge${targetName}Assets")
|
90
|
|
-
|
91
|
|
- runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask)
|
92
|
|
- runBefore("processX86${targetName}Resources", currentBundleTask)
|
93
|
|
- runBefore("processUniversal${targetName}Resources", currentBundleTask)
|
94
|
|
- runBefore("process${targetName}Resources", currentBundleTask)
|
95
|
|
- }
|
96
|
|
- }
|
97
|
|
-}
|