diff --git a/.DS_Store b/.DS_Store index 798f8495..73830414 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README-zh.md b/README-zh.md index ca843165..46af45e7 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,11 +1,11 @@ # Robust - [![Download](https://api.bintray.com/packages/meituan/maven/com.meituan.robust%3Apatch/images/download.svg?version=0.4.7) ](https://bintray.com/meituan/maven/com.meituan.robust%3Apatch/0.4.7/link) + [![Download](https://api.bintray.com/packages/meituan/maven/com.meituan.robust%3Apatch/images/download.svg?version=0.4.71) ](https://bintray.com/meituan/maven/com.meituan.robust%3Apatch/0.4.71/link) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Meituan-Dianping/Robust/pulls) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/Meituan-Dianping/Robust/master/LICENSE) - 新一代热更新系统Robust,对Android版本无差别兼容。无需发版就可以做到随时修改线上bug,快速对重大线上问题0.4.7作出反应,补丁修补成功率高达99.9%。 + 新一代热更新系统Robust,对Android版本无差别兼容。无需发版就可以做到随时修改线上bug,快速对重大线上问题作出反应,补丁修补成功率高达99.9%。 [English Introduction](README.md) @@ -28,7 +28,7 @@ apply plugin: 'robust' - compile 'com.meituan.robust:robust:0.4.7' + compile 'com.meituan.robust:robust:0.4.71' ``` 2. 在整个项目的build.gradle加入classpath @@ -39,8 +39,8 @@ jcenter() } dependencies { - classpath 'com.meituan.robust:gradle-plugin:0.4.7' - classpath 'com.meituan.robust:auto-patch-plugin:0.4.7' + classpath 'com.meituan.robust:gradle-plugin:0.4.71' + classpath 'com.meituan.robust:auto-patch-plugin:0.4.71' } } ``` diff --git a/README.md b/README.md index d5265a0d..fa1f0376 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Robust -[![Download](https://api.bintray.com/packages/meituan/maven/com.meituan.robust%3Apatch/images/download.svg?version=0.4.7) ](https://bintray.com/meituan/maven/com.meituan.robust%3Apatch/0.4.7/link) +[![Download](https://api.bintray.com/packages/meituan/maven/com.meituan.robust%3Apatch/images/download.svg?version=0.4.71) ](https://bintray.com/meituan/maven/com.meituan.robust%3Apatch/0.4.71/link) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Meituan-Dianping/Robust/pulls) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/Meituan-Dianping/Robust/master/LICENSE) @@ -26,7 +26,7 @@ Robust is an Android HotFix solution with high compatibility and high stability. //please uncomment fellow line before you build a patch //apply plugin: 'auto-patch-plugin' apply plugin: 'robust' - compile 'com.meituan.robust:robust:0.4.7' + compile 'com.meituan.robust:robust:0.4.71' ``` 2. Add below codes in the outest project's build.gradle file. @@ -36,8 +36,8 @@ Robust is an Android HotFix solution with high compatibility and high stability. jcenter() } dependencies { - classpath 'com.meituan.robust:gradle-plugin:0.4.7' - classpath 'com.meituan.robust:auto-patch-plugin:0.4.7' + classpath 'com.meituan.robust:gradle-plugin:0.4.71' + classpath 'com.meituan.robust:auto-patch-plugin:0.4.71' } } ``` diff --git a/auto-patch-plugin/src/main/java/com/meituan/robust/autopatch/PatchesControlFactory.java b/auto-patch-plugin/src/main/java/com/meituan/robust/autopatch/PatchesControlFactory.java index 3daf1c9b..7d9affba 100644 --- a/auto-patch-plugin/src/main/java/com/meituan/robust/autopatch/PatchesControlFactory.java +++ b/auto-patch-plugin/src/main/java/com/meituan/robust/autopatch/PatchesControlFactory.java @@ -59,7 +59,7 @@ static String getAccessDispatchMethodBody(CtClass patchClass, String modifiedCla accessDispatchMethodBody.append(" android.util.Log.d(\"robust\",\"keyToValueRelation not contain\" );"); } accessDispatchMethodBody.append("patch=new " + patchClass.getName() + "(paramArrayOfObject[paramArrayOfObject.length - 1]);\n"); - accessDispatchMethodBody.append(" keyToValueRelation.put(paramArrayOfObject[paramArrayOfObject.length - 1], patch);\n"); + accessDispatchMethodBody.append(" keyToValueRelation.put(paramArrayOfObject[paramArrayOfObject.length - 1], null);\n"); accessDispatchMethodBody.append("}else{"); accessDispatchMethodBody.append("patch=(" + patchClass.getName() + ") keyToValueRelation.get(paramArrayOfObject[paramArrayOfObject.length - 1]);\n"); accessDispatchMethodBody.append("}"); @@ -125,11 +125,19 @@ static String getAccessDispatchMethodBody(CtClass patchClass, String modifiedCla } } for (int index = 0; index < parametertypes.length; index++) { + if (booleanPrimeType(parametertypes[index].getName())){ + accessDispatchMethodBody.append("((" + JavaUtils.getWrapperClass(parametertypes[index].getName()) + ") (fixObj(paramArrayOfObject[" + index + "]))"); + accessDispatchMethodBody.append(")" + JavaUtils.wrapperToPrime(parametertypes[index].getName())); + if (index != parametertypes.length - 1) { + accessDispatchMethodBody.append(","); + } + } else { accessDispatchMethodBody.append("((" + JavaUtils.getWrapperClass(parametertypes[index].getName()) + ") (paramArrayOfObject[" + index + "])"); accessDispatchMethodBody.append(")" + JavaUtils.wrapperToPrime(parametertypes[index].getName())); if (index != parametertypes.length - 1) { accessDispatchMethodBody.append(","); } + } } accessDispatchMethodBody.append("));}\n"); } @@ -173,4 +181,8 @@ public static CtClass createPatchesControl(CtClass modifiedClass) throws Excepti return patchesControlFactory.createControlClass(modifiedClass); } + public static boolean booleanPrimeType(String typeName) { + return "boolean".equals(typeName); + } + } diff --git a/autopatchbase/src/main/java/com/meituan/robust/utils/PatchTemplate.java b/autopatchbase/src/main/java/com/meituan/robust/utils/PatchTemplate.java index 430a0d6b..be48dcf3 100644 --- a/autopatchbase/src/main/java/com/meituan/robust/utils/PatchTemplate.java +++ b/autopatchbase/src/main/java/com/meituan/robust/utils/PatchTemplate.java @@ -26,4 +26,14 @@ public Object accessDispatch(String methodName, Object[] paramArrayOfObject) { public boolean isSupport(String methodName, Object[] paramArrayOfObject) { return true; } + + //解决boolean被优化成byte的问题 + private static Object fixObj(Object booleanObj) { + if (booleanObj instanceof Byte) { + byte byteValue = (Byte) booleanObj; + boolean booleanValue = byteValue != 0x00; + return new Boolean(booleanValue); + } + return booleanObj; + } } diff --git a/build.gradle b/build.gradle index 85388b4c..ed6fd200 100644 --- a/build.gradle +++ b/build.gradle @@ -9,8 +9,8 @@ buildscript { classpath 'com.android.tools.build:gradle:2.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath 'com.meituan.robust:gradle-plugin:0.4.7' - classpath 'com.meituan.robust:auto-patch-plugin:0.4.7' + classpath 'com.meituan.robust:gradle-plugin:0.4.71' + classpath 'com.meituan.robust:auto-patch-plugin:0.4.71' classpath 'me.tatarka:gradle-retrolambda:3.2.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' diff --git a/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy b/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy index 9dc17133..2d876d0c 100755 --- a/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy +++ b/gradle-plugin/src/main/groovy/robust/gradle/plugin/RobustApkHashAction.groovy @@ -3,13 +3,11 @@ package robust.gradle.plugin import com.meituan.robust.Constants import org.gradle.api.Action import org.gradle.api.Project +import org.gradle.api.file.FileCollection import java.security.MessageDigest - /** * Created by hedex on 17/2/14. - * - * calculate unique string for each apk,you can get the string in file located in build/outputs/robust/robust.apkhash */ class RobustApkHashAction implements Action { @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