Last active
August 23, 2018 07:46
-
-
Save sjchmiela/c73b16008d886f2f55308c7e495479f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gradle script for detached apps. | |
import org.apache.tools.ant.taskdefs.condition.Os | |
void runBefore(String dependentTaskName, Task task) { | |
Task dependentTask = tasks.findByPath(dependentTaskName); | |
if (dependentTask != null) { | |
dependentTask.dependsOn task | |
} | |
} | |
afterEvaluate { | |
def expoRoot = file("../../") | |
def inputExcludes = ["android/**", "ios/**"] | |
task exponentPrebuildStep(type: Exec) { | |
workingDir expoRoot | |
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
commandLine "cmd", "/c", ".\\android\\detach-scripts\\run-exp.bat" | |
} else { | |
commandLine "./android/detach-scripts/run-exp.sh", "prepare-detached-build", "--platform", "android", expoRoot | |
} | |
} | |
runBefore("preBuild", exponentPrebuildStep) | |
// Based on https://github.com/facebook/react-native/blob/master/react.gradle | |
android.applicationVariants.each { variant -> | |
def targetName = variant.name.capitalize() | |
def targetPath = variant.dirName | |
def assetsDir = file("$buildDir/intermediates/assets/${targetPath}") | |
// Bundle task name for variant | |
def bundleExpoAssetsTaskName = "bundle${targetName}ExpoAssets" | |
def currentBundleTask = tasks.create( | |
name: bundleExpoAssetsTaskName, | |
type: Exec) { | |
description = "Expo bundle assets for ${targetName}." | |
// Create dirs if they are not there (e.g. the "clean" task just ran) | |
doFirst { | |
assetsDir.mkdirs() | |
} | |
// Set up inputs and outputs so gradle can cache the result | |
inputs.files fileTree(dir: expoRoot, excludes: inputExcludes) | |
outputs.dir assetsDir | |
// Set up the call to exp | |
workingDir expoRoot | |
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
commandLine("cmd", "/c", ".\\android\\detach-scripts\\run-exp.bat", "bundle-assets", expoRoot, "--platform", "android", "--dest", assetsDir) | |
} else { | |
commandLine("./android/detach-scripts/run-exp.sh", "bundle-assets", expoRoot, "--platform", "android", "--dest", assetsDir) | |
} | |
enabled targetName.toLowerCase().contains("release") || targetName.toLowerCase().contains("prod") | |
} | |
currentBundleTask.dependsOn("merge${targetName}Resources") | |
currentBundleTask.dependsOn("merge${targetName}Assets") | |
runBefore("process${targetName}Resources", currentBundleTask) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gradle script for detached apps. | |
import org.apache.tools.ant.taskdefs.condition.Os | |
void runBefore(String dependentTaskName, Task task) { | |
Task dependentTask = tasks.findByPath(dependentTaskName); | |
if (dependentTask != null) { | |
dependentTask.dependsOn task | |
} | |
} | |
afterEvaluate { | |
def expoRoot = file("../../") | |
def inputExcludes = ["android/**", "ios/**"] | |
task exponentPrebuildStep(type: Exec) { | |
workingDir expoRoot | |
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
commandLine "cmd", "/c", ".\\node_modules\\expokit\\detach-scripts\\run-exp.bat" | |
} else { | |
commandLine "./node_modules/expokit/detach-scripts/run-exp.sh", "prepare-detached-build", "--platform", "android", expoRoot | |
} | |
} | |
runBefore("preBuild", exponentPrebuildStep) | |
// Based on https://github.com/facebook/react-native/blob/master/react.gradle | |
android.applicationVariants.each { variant -> | |
def targetName = variant.name.capitalize() | |
def targetPath = variant.dirName | |
def assetsDir = file("$buildDir/intermediates/assets/${targetPath}") | |
// Bundle task name for variant | |
def bundleExpoAssetsTaskName = "bundle${targetName}ExpoAssets" | |
def currentBundleTask = tasks.create( | |
name: bundleExpoAssetsTaskName, | |
type: Exec) { | |
description = "Expo bundle assets for ${targetName}." | |
// Create dirs if they are not there (e.g. the "clean" task just ran) | |
doFirst { | |
assetsDir.mkdirs() | |
} | |
// Set up inputs and outputs so gradle can cache the result | |
inputs.files fileTree(dir: expoRoot, excludes: inputExcludes) | |
outputs.dir assetsDir | |
// Set up the call to exp | |
workingDir expoRoot | |
if (Os.isFamily(Os.FAMILY_WINDOWS)) { | |
commandLine("cmd", "/c", ".\\node_modules\\expokit\\detach-scripts\\run-exp.bat", "bundle-assets", expoRoot, "--platform", "android", "--dest", assetsDir) | |
} else { | |
commandLine("./node_modules/expokit/detach-scripts/run-exp.sh", "bundle-assets", expoRoot, "--platform", "android", "--dest", assetsDir) | |
} | |
enabled targetName.toLowerCase().contains("release") || targetName.toLowerCase().contains("prod") | |
} | |
currentBundleTask.dependsOn("merge${targetName}Resources") | |
currentBundleTask.dependsOn("merge${targetName}Assets") | |
runBefore("process${targetName}Resources", currentBundleTask) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment