Skip to content

Commit

Permalink
Merge pull request #42 from Meituan-Dianping/develop
Browse files Browse the repository at this point in the history
support windows
  • Loading branch information
mivanzhang authored Mar 28, 2017
2 parents 7fdf49b + 9eae741 commit d9a1899
Show file tree
Hide file tree
Showing 41 changed files with 304 additions and 212 deletions.
15 changes: 8 additions & 7 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# 环境

* Mac or Linux
* Mac Linux Windows
* Gradle 2.10+
* Java 1.7 +

Expand All @@ -26,7 +26,7 @@
apply plugin: 'robust'
compile 'com.meituan.robust:robust:0.3.0'
compile 'com.meituan.robust:robust:0.3.1'
```
2. 在整个项目的build.gradle加入classpath
Expand All @@ -37,8 +37,8 @@
jcenter()
}
dependencies {
classpath 'com.meituan.robust:gradle-plugin:0.3.0'
classpath 'com.meituan.robust:auto-patch-plugin:0.3.0'
classpath 'com.meituan.robust:gradle-plugin:0.3.1'
classpath 'com.meituan.robust:auto-patch-plugin:0.3.1'
}
}
```
Expand All @@ -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
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
[![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 is an Android HotFix solution with high compatibility and high stability.Robust can fix bugs immediately without publishing apk.
Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without publishing apk.

[中文说明](README-zh.md)

# Environment

* Mac or Linux
* Mac Linux and Windows
* Gradle 2.10+
* Java 1.7 +

Expand All @@ -24,7 +24,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.3.0'
compile 'com.meituan.robust:robust:0.3.1'
```
2. Add below codes in the outest project's build.gradle file.

Expand All @@ -34,8 +34,8 @@ Robust is an Android HotFix solution with high compatibility and high stability.
jcenter()
}
dependencies {
classpath 'com.meituan.robust:gradle-plugin:0.3.0'
classpath 'com.meituan.robust:auto-patch-plugin:0.3.0'
classpath 'com.meituan.robust:gradle-plugin:0.3.1'
classpath 'com.meituan.robust:auto-patch-plugin:0.3.1'
}
}
```
Expand All @@ -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
2 changes: 1 addition & 1 deletion 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: 'robust'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
Expand Down
4 changes: 4 additions & 0 deletions app/robust.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<!--是否在补丁加上log,建议上线的时候这个开关的值为false,测试的时候为true-->
<!--<patchLog>true</patchLog>-->
<patchLog>false</patchLog>

<!--项目是否支持progaurd-->
<proguard>true</proguard>
<!--<proguard>false</proguard>-->
</switch>

<!--需要热补的包名或者类名,这些包名下的所有类都被会插入代码-->
Expand Down
Binary file modified app/robust/app-release.apk
Binary file not shown.
Binary file modified app/robust/methodsMap.robust
Binary file not shown.
Binary file removed app/robust/patch.jar
Binary file not shown.
87 changes: 45 additions & 42 deletions app/src/main/java/com/meituan/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package com.meituan.sample;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.meituan.Hll;
import com.meituan.sample.robusttest.other.Hll;
import com.meituan.robust.Patch;
import com.meituan.robust.PatchExecutor;
import com.meituan.robust.RobustCallBack;

import java.lang.reflect.Constructor;
import com.meituan.sample.robusttest.ImageQualityUtil;
import com.meituan.sample.robusttest.NoField;
import com.meituan.sample.robusttest.SampleClass;
import com.meituan.sample.robusttest.State;
import com.meituan.sample.robusttest.Super;

/**
*
* For users of Robust you may only to use MainActivity or SecondActivity,other classes are used for test.<br>
*<br>
* If you just want to use Robust ,we recommend you just focus on MainActivity SecondActivity and PatchManipulateImp.Especially three buttons in MainActivity<br>
*<br>
* in the MainActivity have three buttons; "SHOW TEXT " Button will change the text in the MainActivity,you can patch the show text.<br>
*<br>
* "PATCH" button will load the patch ,the patch path can be configured in PatchManipulateImp.<br>
*<br>
* "JUMP_SECOND_ACTIVITY" button will jump to the second ACTIVITY,so you can patch a Activity.<br>
*<br>
* Attention to this ,We recommend that one patch is just for one built apk ,because every built apk has its unique mapping.txt and resource id<br>
*
*@author mivanzhang
*/

public class MainActivity extends AppCompatActivity {

Expand All @@ -26,49 +44,27 @@ public class MainActivity extends AppCompatActivity {

Hll hll = new Hll(false);


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
textView = (TextView) findViewById(R.id.textView);
state = new State<>(hll);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//除了get方法有拦截之外,其他的几个方法没有做拦截,可能是处理get set方法的误杀
Toast.makeText(MainActivity.this, "arrived in ", Toast.LENGTH_SHORT).show();
state.setIndex(hll, 1, 1l, new Object());
Log.d("robust", "state.get() " + state.get().toString());
Log.d("robust", " state.getIndex() " + state.getIndex());
Super s = new Super();
Log.d("robust", "patch result before :" + s.check());
Log.d("robust", "patch result after:" + s.protextedMethod());
textView.setText(s.getText());
s.getinstance();
// Log.d("robust", "s.getinstance(new Super())== : " + s.getinstance(new Super()));
}
});
Button patch = (Button) findViewById(R.id.patch);
//beigin to patch
patch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// PatchUtils.applyPatch(MainActivity.this, "group", "1.0", "channel", 1233445l, "qwertyuiop1", "QQQQQQQQQQQ");
new PatchExecutor(getApplicationContext(), new PatchManipulateImp(), new Callback()).start();

}
});

try {
ImageQualityUtil.loadImage(null, null, null, 1, null);
} catch (Exception e) {
e.printStackTrace();
}
findViewById(R.id.jump_second_activity).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = (Intent) invokeReflectConstruct("android.content.Intent", new Object[]{MainActivity.this, SecondActivity.class}, new Class[]{Context.class, Class.class});
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
Log.d("robusttest", (new NoField()).toString());
Log.d("robusttest", ImageQualityUtil.getDefaultSize("asdasdasd"));
Expand All @@ -77,6 +73,26 @@ public void onClick(View v) {
}
});

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "arrived in ", Toast.LENGTH_SHORT).show();
state.setIndex(hll, 1, 1l, new Object());
Log.d("robust", "state.get() " + state.get().toString());
Log.d("robust", " state.getIndex() " + state.getIndex());
Super s = new Super();
Log.d("robust", "patch result before :" + s.check());
Log.d("robust", "patch result after:" + s.protextedMethod());
textView.setText(s.getText());
s.getinstance();
}
});
//test situation,
try {
ImageQualityUtil.loadImage(null, null, null, 1, null);
} catch (Exception e) {
e.printStackTrace();
}
}
//patch data report
class Callback implements RobustCallBack {
Expand Down Expand Up @@ -109,17 +125,4 @@ public void exceptionNotify(Throwable throwable, String where) {
}


public static Object invokeReflectConstruct(String className, Object[] parameter, Class[] args) {
try {
Class clazz = Class.forName(className);
Constructor constructor = clazz.getDeclaredConstructor(args);
constructor.setAccessible(true);
return constructor.newInstance(parameter);
} catch (Exception e) {
Log.d("robust", "invokeReflectConstruct construct error " + className + " parameter " + parameter);
e.printStackTrace();
}
throw new RuntimeException("invokeReflectConstruct error ");
}

}
28 changes: 27 additions & 1 deletion app/src/main/java/com/meituan/sample/PatchManipulateImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,54 @@

/**
* Created by mivanzhang on 17/2/27.
*
* We recommend you rewrite your own PatchManipulate class ,adding your special patch Strategy,in the demo we just load the patch directly
*
* <br>
* Pay attention to the difference of patch's LocalPath and patch's TempPath
*
* <br>
* We recommend LocalPath store the origin patch.jar which may be encrypted,while TempPath is the true runnable jar
*/

public class PatchManipulateImp extends PatchManipulate {
@Override
protected List<Patch> fetchPatchList(Context context) {
//将app自己的robustApkHash上报给服务端,服务端根据robustApkHash来区分每一次apk build来给app下发补丁
//apkhash is the unique identifier for apk,so you cannnot patch wrong apk.
//String robustApkHash = RobustApkHashUtils.readRobustApkHash(context);
Patch patch = new Patch();
patch.setName("123");
patch.setLocalPath(Environment.getExternalStorageDirectory().getPath()+ File.separator+"robust"+File.separator + "patch.dex");
//we recommend LocalPath store the origin patch.jar which may be encrypted,while TempPath is the true runnable jar
patch.setLocalPath(Environment.getExternalStorageDirectory().getPath()+ File.separator+"robust"+File.separator + "patch.jar");
patch.setTempPath(Environment.getExternalStorageDirectory().getPath()+ File.separator+"robust"+File.separator + "patch");
patch.setPatchesInfoImplClassFullName("com.meituan.robust.patch.PatchesInfoImpl");
List patches = new ArrayList<Patch>();
patches.add(patch);
return patches;
}

/**
*
* @param context
* @param patch
* @return
*
* you can verify your patches here
*/
@Override

protected boolean verifyPatch(Context context, Patch patch) {
return true;
}

/**
*
* @param patch
* @return
*
* you may download your patches here
*/
@Override
protected boolean ensurePatchExist(Patch patch) {
return true;
Expand Down
Loading

0 comments on commit d9a1899

Please sign in to comment.