From 28d2aa041bfe9a1102b5890a588af3b51745f2d9 Mon Sep 17 00:00:00 2001 From: hedex Date: Sun, 29 Oct 2017 10:45:00 +0800 Subject: [PATCH] adapt gradle plugin 3.0.0 fix WeakHashMap OOM question fix method with boolean param Signed-off-by: hedex --- .DS_Store | Bin 6148 -> 10244 bytes README-zh.md | 10 +-- README.md | 8 +- .../autopatch/PatchesControlFactory.java | 14 ++- .../meituan/robust/utils/PatchTemplate.java | 10 +++ build.gradle | 4 +- .../gradle/plugin/RobustApkHashAction.groovy | 82 ++++++++++++++++-- .../plugin/RobustApkHashZipUtils.groovy | 13 ++- gradle.properties | 2 +- 9 files changed, 121 insertions(+), 22 deletions(-) diff --git a/.DS_Store b/.DS_Store index 798f849580e8fc8e4c95a2a517365b81fe950ac5..738304140900f427dbef5dd0a7b8ae4ee3b1cabe 100644 GIT binary patch literal 10244 zcmeHNPfrs;6n{%wXsIM6Y9w&kBPKvfTHsnMax;?DK#UOBZJTz((rwx;jUgoUs)D=%%oG4nl9kLj zfC>OXyhujQVAZ6Mp00+{#e2q3Du@TjfC*VMH=asc4c4+lG9Vd{3`hnf1CoKifdTwx zQwfG0DQn4qWI!@dXMolR6)%zrE^CftO9xhL3xLv(-K=06_W=x}a+%<==12xbpU&<< z;ZTKdF%$=mdX>ykCb+CQ(t(5Gz(L_7D}0Bdu+b5xGILN8j+C`zKr+zC0PWp-U<`6l z0!`e%uNIl{wS$pHi&blSI#aRJ0NeXpubABtAFEd87>i<_P6_xZvo&%Oz&H$yAq$#w zhQPJK2NZ*#b;sWszW<1z;KS&PP}HmCqHbC`_Waa~rct(|(T_@(&mZXS35I&Z;c#y_ z(%-w7%3IZxt=W}wQY+nLcSa_w^Y*M}=MUT0Ez7L8HGR&=R+l2@E?Wg#GYZ*~09}|j z3K^@Kv?_&6c_HQan>R9cekpQ(wv=5%=&V-A&KYGxH%!C66%2(!!O&74w^H;Nl~9zS{dZ1efn>o+W6Q20s+XPx_c{T5rC z4iAlc``=xSOX2R|rw9*eb{vm4bR0j-`{)#b n71SrFfwJaEY+?E1KL+4`DY@Gtx&N2@|KHrbyARPnxBveI3kQbS delta 310 zcmZn(XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$SANeU^g?Pz-AtSK1M;)S{;RI zb8`b71ruYl+FF4plUECROFOk32kKyENMtBrD9FusaY-pHNoHWUs?jVnSx`vK48#B` zfGa7;Fbq!4&n*CpxqvCC=Ca_Tyqx^Jbf665 { @Override @@ -25,6 +23,68 @@ class RobustApkHashAction implements Action { // project.logger.quiet("===start compute robust apk hash===") // def startTime = System.currentTimeMillis() List partFiles = new ArrayList<>() + + if (isGradlePlugin300orAbove()){ + //protected FileCollection resourceFiles; + FileCollection resourceFiles = packageTask.resourceFiles + if (null == resourceFiles) { + return + } + partFiles.add(resourceFiles.getFiles()) + + //protected FileCollection dexFolders; + FileCollection dexFolders = null + try { + dexFolders = packageTask.dexFolders + } catch (MissingPropertyException e) { + // api is not public + } + if (null != dexFolders) { + partFiles.addAll(dexFolders.getFiles()) + } + + //protected FileCollection javaResourceFiles; + FileCollection javaResourceFiles = null + try { + javaResourceFiles = packageTask.javaResourceFiles + } catch (MissingPropertyException e) { + // api is not public + } + if (null != javaResourceFiles) { + partFiles.addAll(javaResourceFiles.getFiles()) + } + + //protected FileCollection jniFolders; + FileCollection jniFolders = null + try { + jniFolders = packageTask.jniFolders + } catch (MissingPropertyException e) { + // api is not public + } + if (null != jniFolders) { + partFiles.addAll(jniFolders.getFiles()) + } + + //protected FileCollection assets; + FileCollection assets = null; + try { + assets = packageTask.assets + } catch (MissingPropertyException e) { + } + if (null != assets) { + partFiles.add(assets.getFiles()) + } + + String robustHash = computeRobustHash(partFiles) + + if (assets instanceof FileCollection) { + FileCollection assetsFileCollection = (FileCollection) assets; + createHashFile(assetsFileCollection.asPath, Constants.ROBUST_APK_HASH_FILE_NAME, robustHash) + } + return + + } else { + File resourceFile = packageTask.resourceFile if (null == resourceFile) { return @@ -63,11 +123,6 @@ class RobustApkHashAction implements Action { } - try { - } catch (MissingPropertyException e) { - // api is not public - } - File assets = null; try { assets = packageTask.assets @@ -97,6 +152,7 @@ class RobustApkHashAction implements Action { // logger.quiet "robust apk hash is $robustHash" // logger.quiet "compute robust apk hash cost $cost second" // project.logger.quiet("===compute robust apk hash end===") + } } } } @@ -145,4 +201,14 @@ class RobustApkHashAction implements Action { fileWriter.close() return hashFile } + + public static boolean isGradlePlugin300orAbove() { + try { + String gradlePluginVersion = com.android.builder.Version.ANDROID_GRADLE_PLUGIN_VERSION + return gradlePluginVersion.compareTo("3.0.0") >= 0; + } catch (Throwable throwable) { + + } + return false; + } } \ No newline at end of file diff --git a/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashZipUtils.groovy b/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashZipUtils.groovy index baeeba8e..dd3e0a12 100755 --- a/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashZipUtils.groovy +++ b/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashZipUtils.groovy @@ -12,7 +12,18 @@ class RobustApkHashZipUtils { ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(output)); zipOut.setLevel(Deflater.BEST_SPEED); - for (File source : sources) { + List fileList = new LinkedList(); + for (Object source : sources) { + if (source instanceof File){ + fileList.add(source) + } else if (source instanceof Collection){ + fileList.addAll(source) + } else { + System.err.println("packZip source 4" + source.getClass()) + } + } + + for (File source : fileList) { if (source.isDirectory()) { zipDir(zipOut, "", source); } else { diff --git a/gradle.properties b/gradle.properties index 6623c229..4e5bf0a9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,6 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=0.4.7 +VERSION_NAME=0.4.71 GROUP=com.meituan.robust