I've got some assets for my Android project that aren't checked in with the source, but instead get downloaded by the build system. I've figured out how to download and extract them in gradle, but I seem to be doing it too late in the build process, because they aren't getting copied to the apk.
def assetsDir = new File(projectDir, 'src/main/assets')
task extractAssets(type: Exec) {
def wd = assetsDir
def extractDir = 'extractedStuff'
outputs.dir "${wd}/${extractDir}"
workingDir wd
commandLine 'tar', 'xzf', 'assets-to-extract.tgz', extractDir
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn extractAssets
}
The first time I run this after a clean, it extracts the assets into the assets directory, but doesn't include them in my apk. After that, whenever I build, it includes the assets in the apk. My conclusion is that I should make my extractAssets task happen earlier in the build process (before mergeAssets maybe?). If so, where do I add the dependsOn?