From 5c985e7a0c12609d8b7e56a553d2c927b0f5dcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E9=83=81?= Date: Tue, 21 Mar 2017 17:15:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=85=A8=E9=87=8Fdiff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/taobao/android/TPatchTool.java | 72 +++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/atlas-gradle-plugin/dexpatch/src/main/java/com/taobao/android/TPatchTool.java b/atlas-gradle-plugin/dexpatch/src/main/java/com/taobao/android/TPatchTool.java index d86e0750a..39be753f8 100644 --- a/atlas-gradle-plugin/dexpatch/src/main/java/com/taobao/android/TPatchTool.java +++ b/atlas-gradle-plugin/dexpatch/src/main/java/com/taobao/android/TPatchTool.java @@ -249,17 +249,14 @@ import java.net.URL; import java.net.URLConnection; import java.sql.Date; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; /** * 生成为atlas做动态部署的diff工具类 @@ -296,6 +293,12 @@ public class TPatchTool extends BasePatchTool { protected File baseApkFileList; + public void setCreateAll(boolean createAll) { + this.createAll = createAll; + } + + private boolean createAll = false; + public String getDexcode() { return dexcode; } @@ -453,7 +456,7 @@ public Boolean call() throws Exception { // 压缩patch文件夹,得到tpatch文件 File patchFile = createTPatchFile(outPatchDir, patchTmpDir); - PatchInfo curPatchInfo = createBasePatchInfo(patchFile.getName()); + PatchInfo curPatchInfo = createBasePatchInfo(patchFile); BuildPatchInfos buildPatchInfos = null; // 生成多版本的tpatch文件 buildPatchInfos = createIncrementPatchFiles(productName, @@ -570,7 +573,7 @@ private void processBundleFiles(File newBundleFile, File diffTxtFile) throws IOException, RecognitionException, PatchException { String bundleName = FilenameUtils.getBaseName(newBundleFile.getName()); File destPatchBundleDir = new File(patchTmpDir, bundleName); - if (!isModifyBundle(newBundleFile.getName())) { + if (!isModifyBundle(newBundleFile.getName())&&!createAll) { return; } final File newBundleUnzipFolder = new File(newBundleFile.getParentFile(), bundleName); @@ -775,11 +778,28 @@ private File unzipApk(File outPatchDir) { * @param fileName * @return */ - public PatchInfo createBasePatchInfo(String fileName) { + public PatchInfo createBasePatchInfo(File file) { PatchInfo patchInfo = new PatchInfo(); patchInfo.setPatchVersion(newApkVersion); patchInfo.setTargetVersion(baseApkVersion); - patchInfo.setFileName(fileName); + patchInfo.setFileName(file.getName()); + SetmodifyBundles = new HashSet<>(); + ZipFile zipFile = newZipFile(file); + Enumeration enumeration = zipFile.entries(); + while (enumeration.hasMoreElements()){ + ZipEntry zipEntry = enumeration.nextElement(); + if (zipEntry.getName().startsWith("lib")&&zipEntry.getName().indexOf(File.separator)!= -1){ + modifyBundles.add(zipEntry.getName().substring(3,zipEntry.getName().indexOf(File.separator)).replace("_",".")); + }else if (zipEntry.getName().endsWith(".so")&&zipEntry.getName().indexOf(File.separator)== -1){ + modifyBundles.add(zipEntry.getName().substring(3,zipEntry.getName().lastIndexOf(".")).replace("_",".")); + } + + } + try { + zipFile.close(); + } catch (IOException e) { + e.printStackTrace(); + } for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) { if (artifactBundleInfo.getMainBundle()) { if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || hasMainBundle) { @@ -809,12 +829,35 @@ public PatchInfo createBasePatchInfo(String fileName) { patchBundleInfo.setDependency(artifactBundleInfo.getDependency()); // patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion()); patchInfo.getBundles().add(patchBundleInfo); + }else if (modifyBundles.contains(artifactBundleInfo.getPkgName())){ + PatchBundleInfo patchBundleInfo = new PatchBundleInfo(); + patchBundleInfo.setNewBundle(false); + patchBundleInfo.setMainBundle(false); + patchBundleInfo.setVersion(artifactBundleInfo.getVersion()); + patchBundleInfo.setName(artifactBundleInfo.getName()); + patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName()); + patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId()); + patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName()); + patchBundleInfo.setDependency(artifactBundleInfo.getDependency()); + // patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion()); + patchInfo.getBundles().add(patchBundleInfo); } } + + return patchInfo; } + private ZipFile newZipFile(File file) { + try { + return new ZipFile(file); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + /** * 生成增量的patch文件 */ @@ -1157,16 +1200,16 @@ public static void main(String[] args) throws Exception { // URL url1 = new URL(aaa.substring(1,aaa.length()-1)); //// downloadTPath(aaa.substring(1,aaa.length()-1), new File("/Users/lilong/Downloads/1111.patch")); //// PatchUtils.getTpatchClassDef(lastPatchFile, bundleClassMap) - Map> bundleClassMap = new ConcurrentHashMap>(); - PatchUtils.getTpatchClassDef(new File("/Users/lilong/Downloads/temp/patch-6.1.1@6.1.0.zip"), - bundleClassMap); - System.out.println(bundleClassMap.size()); +// Map> bundleClassMap = new ConcurrentHashMap>(); +// PatchUtils.getTpatchClassDef(new File("/Users/lilong/Downloads/temp/patch-6.1.1@6.1.0.zip"), +// bundleClassMap); +// System.out.println(bundleClassMap.size()); TPatchTool tPatchTool = new TPatchTool(new File("/Users/lilong/Downloads/taobao-android.apk"), new File("/Users/lilong/Downloads/tpatch-diff.apk"), "1.0.0", "2.0.0", true); - tPatchTool.bundleClassMap = bundleClassMap; +// tPatchTool.bundleClassMap = bundleClassMap; tPatchTool.doPatch(new File("/Users/lilong/Downloads/aaa"), false, null, @@ -1187,4 +1230,5 @@ public static void main(String[] args) throws Exception { // tPatchTool.doPatch(dexDiffFile,false,null,false,null,null); } + } From 9ddd72eac7a94a2037cfe02b2818ff51819db9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=A5=E9=83=81?= Date: Tue, 21 Mar 2017 17:16:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atlas-demo/AtlasDemo/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas-demo/AtlasDemo/build.gradle b/atlas-demo/AtlasDemo/build.gradle index 4edac6af9..29492c19c 100644 --- a/atlas-demo/AtlasDemo/build.gradle +++ b/atlas-demo/AtlasDemo/build.gradle @@ -13,7 +13,7 @@ buildscript { resolutionStrategy.cacheChangingModulesFor 0, 'seconds' } dependencies { - classpath "com.taobao.android:atlasplugin:2.3.0.alpha2" + classpath "com.taobao.android:atlasplugin:2.3.0.alpha3" } }