I need to pack some text files in a zip file, and put it in the assets
folder of my Android project.
I am using gradle and android studio.
This is what I have in my build.gradle
at the moment:
task textsToZip(type: Zip, description: 'create a zip files with all txts') {
destinationDir file("$buildDir/txts")
baseName 'txts'
extension 'zip'
from fileTree(dir: 'text-files', include: '**/*.txt')
into 'assets'
}
android.applicationVariants.all { variant ->
variant.mergeAssets.dependsOn(textsToZip)
}
This doesn't seem to work, I don't get the txts.zip in the right place. I am quite new to gradle, can someone give me a hint about what I am doing wrong? Thanks!
Ok, at the end I figured it out. I created a task for every variant, this way:
android.applicationVariants.all { variant ->
def zipTask = project.tasks.create "textsToZip${variant.name.capitalize()}", Zip
zipTask.destinationDir = file(variant.processResources.assetsDir)
zipTask.baseName = "txts"
zipTask.extension = "zip"
zipTask.from fileTree(dir: 'text-files', include: '**/*.txt')
variant.processResources.dependsOn(zipTask)
}
I don't know if it's the best way to go, but it worked for me, and I find it also quite elegant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With