import java.security.MessageDigest apply plugin: 'com.android.application' android { compileSdk 28 defaultConfig { applicationId 'com.baidu.paddle.fastdeploy.app.examples' minSdkVersion 15 //noinspection ExpiredTargetSdkVersion targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' //noinspection GradleDependency implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:design:28.0.0' implementation 'org.jetbrains:annotations:15.0' implementation project(path: ':fastdeploy') //noinspection GradleDependency testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } def archives = [ [ 'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_s_320_coco_lcnet.tgz', 'dest' : 'src/main/assets/models' ], [ 'src': 'https://bj.bcebos.com/paddlehub/fastdeploy/picodet_l_320_coco_lcnet.tgz', 'dest' : 'src/main/assets/models' ] ] task downloadAndExtractArchives(type: DefaultTask) { doFirst { println "Downloading and extracting archives including models ..." } doLast { // Prepare cache folder for archives String cachePath = "cache" if (!file("${cachePath}").exists()) { mkdir "${cachePath}" } archives.eachWithIndex { archive, index -> MessageDigest messageDigest = MessageDigest.getInstance('MD5') messageDigest.update(archive.src.bytes) String cacheName = new BigInteger(1, messageDigest.digest()).toString(32) // Download the target archive if not exists boolean copyFiles = !file("${archive.dest}").exists() if (!file("${cachePath}/${cacheName}.tgz").exists()) { ant.get(src: archive.src, dest: file("${cachePath}/${cacheName}.tgz")) copyFiles = true // force to copy files from the latest archive files } // Extract the target archive if its dest path does not exists if (copyFiles) { copy { from tarTree("${cachePath}/${cacheName}.tgz") into "${archive.dest}" } } } } } preBuild.dependsOn downloadAndExtractArchives