1、在项目根目录下创建download_aar.gradle
def app_dir = new File(project.buildDir, 'app_release')
def aar_file = new File(app_dir, 'app_release.aar')//下载aar到这个目录
def libsDir = project.file("libs")//存放aar的libs目录
def app_url = new URL('')//aar的网络路径
//下载aar
def downloadAAR = { URL url, File dest ->
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs()
}
url.withInputStream { i -> dest.withOutputStream { it << i } }
}
//下载任务
task download() {
if (aar_file.exists()) {
delete aar_file
}
downloadAAR(app_url, aar_file)
}
//复制任务
task copyAARToLibs(dependsOn: download) {
copy{
from app_dir
into libsDir
}
}
preBuild.dependsOn copyAARToLibs
2、在app的build.gradle中使用
apply from : '../download_aar.gradle'