Skip to content

Commit

Permalink
Merge pull request #206 from Meituan-Dianping/master-adapt-gradle-too…
Browse files Browse the repository at this point in the history
…ls-3-0-0

adapt gradle plugin 3.0.0
  • Loading branch information
hedex authored Oct 29, 2017
2 parents 85e2ee0 + 28d2aa0 commit f88194e
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 22 deletions.
Binary file modified .DS_Store
Binary file not shown.
10 changes: 5 additions & 5 deletions README-zh.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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
Expand All @@ -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'
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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.

Expand All @@ -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'
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("}");
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
@Override
Expand All @@ -25,6 +23,68 @@ class RobustApkHashAction implements Action<Project> {
// project.logger.quiet("===start compute robust apk hash===")
// def startTime = System.currentTimeMillis()
List<File> 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
Expand Down Expand Up @@ -63,11 +123,6 @@ class RobustApkHashAction implements Action<Project> {
}


try {
} catch (MissingPropertyException e) {
// api is not public
}

File assets = null;
try {
assets = packageTask.assets
Expand Down Expand Up @@ -97,6 +152,7 @@ class RobustApkHashAction implements Action<Project> {
// logger.quiet "robust apk hash is $robustHash"
// logger.quiet "compute robust apk hash cost $cost second"
// project.logger.quiet("===compute robust apk hash end===")
}
}
}
}
Expand Down Expand Up @@ -145,4 +201,14 @@ class RobustApkHashAction implements Action<Project> {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ class RobustApkHashZipUtils {
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(output));
zipOut.setLevel(Deflater.BEST_SPEED);

for (File source : sources) {
List<File> fileList = new LinkedList<File>();
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 {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f88194e

Please sign in to comment.