From 4d734ac297800310997b8190c4c4dbf8fc744e20 Mon Sep 17 00:00:00 2001 From: Thodoris Sotiropoulos Date: Sat, 2 Nov 2019 12:32:24 +0200 Subject: [PATCH] Separate getNativesZipFile and getPrebuiltNatives. Improve code quality. * Fix the task 'getPrebuiltNatives' * Do not replace native if it's newer than zip --- build.gradle | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 14e3209c2..b673bbd4e 100644 --- a/build.gradle +++ b/build.gradle @@ -168,18 +168,23 @@ if(skipPrebuildLibraries!="true"&&buildNativeProjects!="true"){ String nativesZipFile="${rootPath}" + File.separator + "build"+ File.separator +nativesSnasphot+"-natives.zip" String nativesPath="${rootPath}" + File.separator + "build"+ File.separator +"native" - build.dependsOn('getPrebuiltNatives') - task getPrebuiltNatives() { + task getNativesZipFile { + outputs.file nativesZipFile doFirst { File target = file(nativesZipFile); - - if (!target.exists()) { - println("Download natives from "+nativesUrl+" to "+nativesZipFile); - target.getParentFile().mkdirs(); - ant.get(src: nativesUrl, dest: target); - } + println("Download natives from "+nativesUrl+" to "+nativesZipFile); + target.getParentFile().mkdirs(); + ant.get(src: nativesUrl, dest: target); + } + } + task extractPrebuiltNatives { + inputs.file nativesZipFile + outputs.dir nativesPath + dependsOn getNativesZipFile + + doFirst { for(File src : zipTree(nativesZipFile)){ String srcRel=src.getAbsolutePath().substring((int)(nativesZipFile.length()+1)); srcRel=srcRel.substring(srcRel.indexOf("/")+1); @@ -189,29 +194,17 @@ if(skipPrebuildLibraries!="true"&&buildNativeProjects!="true"){ String p1=srcRel.substring(0,j); String p2=srcRel.substring(j); if(!p1.equals("android")&&!p2.startsWith("/native")) srcRel=p1+"/native"+p2; - // - File dest=new File(nativesPath+File.separator+srcRel); - - boolean include=false; - if(!dest.exists()){ - include=true; + boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified()) + if (doCopy) { println("Copy "+src+" "+dest); - }else if(dest.lastModified()