You can use the preBuild
task to download the file before the build and perform the download with this method. The following will download a file into assets
directory of your app
module
android {
preBuild << {
def url = "https://bitbucket.org/HellGate/jquery-slider/raw/5ab0c31aaa57fb7d321076194f462b472f5f031e/index.html"
def file = new File('app/src/main/assets/index.html')
new URL(url).withInputStream{ i -> file.withOutputStream{ it << i }}
}
}
If using private repositories, put your credentials with basic auth scheme username:password
:
android {
preBuild << {
def url = "https://username:password@bitbucket.org/HellGate/jquery-slider/raw/5ab0c31aaa57fb7d321076194f462b472f5f031e/index.html"
def file = new File('app/src/main/assets/index.html')
new URL(url).withInputStream{ i -> file.withOutputStream{ it << i }}
}
}
In this case, you could put them in local.properties
file (for not committing your credentials) :
file_path=app/src/main/assets/index.html
ext_url=https://username:password@bitbucket.org/bertrandmartel/test/raw/c489ae46c3de9ad7089f53660a8de616af08265d/youtube.html
Read the properties in your preBuild
task :
preBuild << {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
if (properties.containsKey("file_path") && properties.containsKey("ext_url")) {
def file = new File(properties.getProperty("file_path"))
def url = properties.getProperty("ext_url")
new URL(url).withInputStream{ i -> file.withOutputStream{ it << i }}
}
else{
println("no properties found")
}
}