Skip to content

Commit

Permalink
Merge pull request #45 from Meituan-Dianping/bugfix/PTI-501
Browse files Browse the repository at this point in the history
Bugfix/PTI 501
  • Loading branch information
mivanzhang authored Mar 28, 2017
2 parents b14e0d9 + 7486b78 commit 9eae741
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 27 deletions.
7 changes: 4 additions & 3 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# AutoPatch


Robust补丁自动化,为Robust自动生成补丁,使用者只需要提交修改完bug后的代码,运行和线上apk打包同样的gradle命令即可,会在项目的app/build/outputs/robust目录下生成补丁。
Robust补丁自动化,为Robust自动生成补丁,使用者只需要提交修改完bug后的代码,运行和线上apk打包同样的gradle命令即可,会在项目的app/build/outputs/robust目录下生成补丁。更多自动化补丁信息请参考:[Android热更新方案Robust开源,新增自动化补丁工具](http://tech.meituan.com/android_autopatch.html)

# 使用方法

Expand Down Expand Up @@ -113,7 +113,7 @@ Robust补丁自动化,为Robust自动生成补丁,使用者只需要提交
```
2. 安装生成的apk。保存mapping.txt文件以及app/build/outputs/robust/methodsMap.robust文件
3. 修改代码之后,加上**@Modify**注解或者调用指定的方法
4. 把保存的mapping.txt和methodsMap.robust放到app/robust目录下
4. 把保存的**mapping.txt****methodsMap.robust**放到app/robust目录下
5. 执行和打包相同的gradle命令:

```java
Expand All @@ -128,7 +128,8 @@ Robust补丁自动化,为Robust自动生成补丁,使用者只需要提交
```
手机上补丁的路径是`PatchManipulateImp`中指定的
8. 打开App,点击Patch按钮就会加载补丁。
9. 也可以加载app/robust的样例dex,修改了Jump_second_Activity跳转Activity的显示文字。
9. 也可以加载app/robust的样例补丁,修改了Jump_second_Activity跳转Activity的显示文字。
10. 在样例中我们给类```SecondActivity```的方法```getTextInfo(String meituan)```制作补丁,你可以自行定制
10. 补丁加载之后每次都会删除,再次运行需要重新copy补丁。

# 注意事项
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ When you build APK,you may need to save mapping.txt and files in build/outputs/r
# AutoPatch


AutoPatch will generate patch for Robust automatically.You just need to fellow below steps to genrate patches.
AutoPatch will generate patch for Robust automatically. You just need to fellow below steps to genrate patches. For more details please visit website http://tech.meituan.com/android_autopatch.html

# Steps

Expand Down Expand Up @@ -111,7 +111,7 @@ AutoPatch will generate patch for Robust automatically.You just need to fellow b
./gradlew clean assembleRelease --stacktrace --no-daemon
```
2. After install apk on your phone,you need to save **mapping.txt** and **app/build/outputs/robust/methodsMap.robust**
3. Put mapping.txt and methodsMap.robust which are generated when you build the apks in diretory **app/robust/**,if not exists ,create it!
3. Put mapping.txt and methodsMap.robust which are generated when you build the apks into diretory **app/robust/**,if directory not exists ,create it!
4. After modifying the code ,please put annotation `@Modify` on the modified methods or invoke `RobustModify.modify()` (designed for Lambda Expression )in the modified methods.
5. Run the same gradle command as you build the apk:

Expand All @@ -126,10 +126,9 @@ AutoPatch will generate patch for Robust automatically.You just need to fellow b
adb push ~/Desktop/code/robust/app/build/outputs/robust/patch.jar /sdcard/robust/patch_temp.jar
```
patch directory can be configured in ``PatchManipulateImp``.
8. Open app,and click patch button,patch is used.

9. Also you can use our sample dex in **app/robust/sample_patch.dex** ,this dex change text after you click **Jump_second_Activity** Button.

8. Open app,and click **Patch** button,patch is used.
9. Also you can use our sample patch in **app/robust/sample_patch.jar** ,this dex change text after you click **Jump_second_Activity** Button.
10. In the demo ,we change the text showed on the second activity which is configured in the method ```getTextInfo(String meituan)``` in class ```SecondActivity```
10. Demo delete patch after used.You should copy patch everytimes.

# Attentions
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
//apply plugin: 'robust'
apply plugin: 'auto-patch-plugin'
//apply plugin: 'auto-patch-plugin'
apply plugin: 'robust'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
Expand Down
Binary file modified app/robust/app-release.apk
Binary file not shown.
28 changes: 15 additions & 13 deletions app/src/main/java/com/meituan/sample/SecondActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ protected void onCreate(Bundle savedInstanceState) {
bundle.putInt("asd",1);
bundle.getFloat("asd");
}
/**
* if you change the return value you will change the show text,in the demo we built a patch to change the text
*/
@Modify
public String getTextInfo(String meituan) {
People p = new People();
p.setName("mivazhang");
p.setCates(" AutoPatch");
people.setName(" I am Patch");
ConcreateClass concreateClass = new ConcreateClass();

// return "you make it!! name is " + p.getName() + " \npatch success " + people.getName() ;
return "error occur " + concreateClass.getA();
}

// another usage of Modify anntation
// @Modify(value = "com.meituan.sample.SecondActivity.onCreate(android.os.Bundle)")
private String getInfo(State stae, Super s, long l) {
Expand All @@ -105,20 +120,7 @@ public View onCreateView(String name, Context context, AttributeSet attrs) {
return super.onCreateView(name, context, attrs);
}

/**
* if you change the return value you will change the show text,in the demo we built a patch to change the text
*/
@Modify
public String getTextInfo(String baidu) {
People p = new People();
p.setName("mivazhang");
p.setCates(" AutoPatch");
people.setName(" I am Patch");
ConcreateClass concreateClass = new ConcreateClass();

return "you make it!! " + p.getName() + baidu + getTextI1(flag) + people.getAddr() + " name is " + people.getName() + " conreate class getA " + concreateClass.getA();
// return "error " + concreateClass.getA();
}


@Add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public int getInt(int dex) {
}

public String getA() {
return "new";
return " !!! ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class PatchesFactory {
}

CtClass temPatchClass = cloneClass(modifiedClass, patchName, methodNoNeedPatchList);
// if (temPatchClass.declaredMethods.size() == 0) {
if (temPatchClass.getDeclaredMethods().length == 0) {
printList(patchMethodSignureSet.toList());
throw new RuntimeException("all methods in patch class are deteted,cannot find patchMethod in class " + temPatchClass.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ReadXML {
Config.mappingFilePath = "${path}${Constants.DEFAULT_MAPPING_FILE}"
}

if (!Config.supportProGuard&&(Config.mappingFilePath == null || "".equals(Config.mappingFilePath) || !(new File(Config.mappingFilePath)).exists())) {
if (Config.supportProGuard&&(Config.mappingFilePath == null || "".equals(Config.mappingFilePath) || !(new File(Config.mappingFilePath)).exists())) {
throw new RuntimeException("Not found ${Config.mappingFilePath}, please put it on your project's robust dir or change your robust.xml !");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import javassist.CtClass

import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.regex.Matcher
/**
* Created by mivanzhang on 16/11/3.
*/
Expand Down

0 comments on commit 9eae741

Please sign in to comment.