Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
s1rius committed Jun 23, 2021
1 parent d6c110f commit ba0ab64
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 108 deletions.
115 changes: 7 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,116 +1,15 @@
# WillFix
# Pudge

基于gradle transform api和ASM的第三方库崩溃修复插件
Pudge 是基于 ByteX 开发的几个字节码插件库的合集

- [Hugo2](https://github.com/s1rius/pudge/tree/master/hugo2-bytex/README.md)

[hugo](https://github.com/JakeWharton/hugo) 使用 ASM 重新实现的插件

### 背景

App在引入第三方库的同时,也引入了第三方法库的bug。第三方团队无法即时修复问题,发布版本。需要App的开发者自行修复bug。

### WillFix是什么

WillFix是一个可以修复其他第三方库崩溃的插件。
通过简单的设置扩展,可以在目标方法中增加TryCatch代码块,捕获造成崩溃的异常

### WillFix的缺陷

WillFix仅能在返回值是空的方法上加TryCatch代码块,或者在返回值是基本类型的方法上加上TryCatch代码块,并返回0
对返回值是数组和类的方法,不做支持。如果需要可以fork代码自己修改

### WillFix的具体实现

[实现方式和步骤](README_DEV.md)

### 快速接入

WillFix 提供两种方式来进行接入

- 单独插件接入
- 作为ByteX字节码插件的子插件接入

1. 单独插件接入

在build.gradle中加入以下代码

```
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
...
classpath "wtf.s1.pudge:will-fix-plugin:${Versions.willFix}"
}
}

dependencies {
...
implementation "wtf.s1.pudge:will-fix-core:${Versions.willFix}"
}
- [WillFix](https://github.com/s1rius/pudge/tree/master/willfix-bytex/README.md)

apply plugin: "s1.willfix"
willFix {
enable true
enableInDebug true
needVerify true
logLevel "INFO"
// 捕获异常之后的处理方法
exceptionHandler "wtf.s1.willfix.ExceptionHandler#log#(Ljava/lang/Exception;)V"
// 示例:需要捕获异常的方法
methodList = [
"wtf.s1.willfix.Test#getMsgSize#()I",
"wtf.s1.willfix.Test#setError#(I)V",
"com.google.firebase.perf.network.InstrumentOkHttpEnqueueCallback#onResponse#(Lokhttp3/Call;Lokhttp3/Response;)V"
]
}
```

2. ByteX子插件接入

在build.gradle中加入以下代码

```
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}
在指定方法的方法体中增加 try catch 块的插件

dependencies {
...
classpath "com.bytedance.android.byteX:base-plugin:${Versions.bytex}"
classpath "wtf.s1.pudge:will-fix-bytex:${Versions.willFix}"
}
}

dependencies {
...
implementation "wtf.s1.pudge:will-fix-core:${Versions.willFix}"
}

apply plugin: 'bytex'
ByteX {
enable true
enableInDebug true
logLevel "DEBUG"
}

apply plugin: "s1.willfix.bytex"
willFixByteX {
enable true
enableInDebug true
logLevel "DEBUG"
exceptionHandler "wtf.s1.willfix.ExceptionHandler#log#(Ljava/lang/Exception;)V"
methodList = [
"wtf.s1.willfix.Test#getMsgSize#()I",
"wtf.s1.willfix.Test#setError#(I)V",
"com.google.firebase.perf.network.InstrumentOkHttpEnqueueCallback#onResponse#(Lokhttp3/Call;Lokhttp3/Response;)V"
]
}
```


69 changes: 69 additions & 0 deletions hugo2-bytex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Hugo2

Hugo2 是借鉴 [hugo](https://github.com/JakeWharton/hugo)[Hunter-Debug](https://github.com/Leaking/Hunter/blob/master/README_hunter_debug.md) 使用 ASM 重新实现的 ByteX 插件

### 快速接入

```
classpath "wtf.s1.pudge:hugo2-bytex:${Versions.pudge}"
// 在 app 模块中加入
apply plugin: "s1.hugo2.bytex"
hugo2ByteX {
enable true
enableInDebug true
logLevel "DEBUG"
}
dependencies {
...
implementation "wtf.s1.pudge:hugo2-core:${Versions.pudge}"
...
}
```

gradle sync 中后,在需要打印Log的类或者方法上增加`@DebugLog`的注解

```
@DebugLog
class Test {
...
}
@DebugLog
fun test() {
...
}
```

在 Application 的初始化方法中加上自定义的Logger

```
class App: Application() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
Hugo2.setLogger(object: Hugo2.Hugo2Logger {
override fun logI(clazz: String, method: String, params: String) {
super.logI(clazz, method, params)
Log.i("hugo", "---> $clazz $method $params")
}
override fun logO(clazz: String, method: String) {
super.logO(clazz, method)
Log.i("hugo", "<--- $clazz $method")
}
})
}
}
```

就可以在LogCat中看到对应方法调用的Log输出了

示例
```
I/hugo: ---> wtf/s1/pudge/Test test7 b=false,i=4,s=null,ooo=[1, 9, 9, 7, 0, 7, 0, 1],
I/hugo: <--- wtf/s1/pudge/Test test7
```
116 changes: 116 additions & 0 deletions willfix-bytex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# WillFix

基于gradle transform api和ASM的第三方库崩溃修复插件


### 背景

App在引入第三方库的同时,也引入了第三方法库的bug。第三方团队无法即时修复问题,发布版本。需要App的开发者自行修复bug。

### WillFix是什么

WillFix是一个可以修复其他第三方库崩溃的插件。
通过简单的设置扩展,可以在目标方法中增加TryCatch代码块,捕获造成崩溃的异常

### WillFix的缺陷

WillFix仅能在返回值是空的方法上加TryCatch代码块,或者在返回值是基本类型的方法上加上TryCatch代码块,并返回0
对返回值是数组和类的方法,不做支持。如果需要可以fork代码自己修改

### WillFix的具体实现

[实现方式和步骤](README_DEV.md)

### 快速接入

WillFix 提供两种方式来进行接入

- 单独插件接入
- 作为ByteX字节码插件的子插件接入

1. 单独插件接入

在build.gradle中加入以下代码

```
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
...
classpath "wtf.s1.pudge:will-fix-plugin:${Versions.willFix}"
}
}

dependencies {
...
implementation "wtf.s1.pudge:will-fix-core:${Versions.willFix}"
}

apply plugin: "s1.willfix"
willFix {
enable true
enableInDebug true
needVerify true
logLevel "INFO"
// 捕获异常之后的处理方法
exceptionHandler "wtf.s1.willfix.ExceptionHandler#log#(Ljava/lang/Exception;)V"
// 示例:需要捕获异常的方法
methodList = [
"wtf.s1.willfix.Test#getMsgSize#()I",
"wtf.s1.willfix.Test#setError#(I)V",
"com.google.firebase.perf.network.InstrumentOkHttpEnqueueCallback#onResponse#(Lokhttp3/Call;Lokhttp3/Response;)V"
]
}
```

2. ByteX子插件接入

在build.gradle中加入以下代码

```
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
...
classpath "com.bytedance.android.byteX:base-plugin:${Versions.bytex}"
classpath "wtf.s1.pudge:will-fix-bytex:${Versions.willFix}"
}
}

dependencies {
...
implementation "wtf.s1.pudge:will-fix-core:${Versions.willFix}"
}

apply plugin: 'bytex'
ByteX {
enable true
enableInDebug true
logLevel "DEBUG"
}

apply plugin: "s1.willfix.bytex"
willFixByteX {
enable true
enableInDebug true
logLevel "DEBUG"
exceptionHandler "wtf.s1.willfix.ExceptionHandler#log#(Ljava/lang/Exception;)V"
methodList = [
"wtf.s1.willfix.Test#getMsgSize#()I",
"wtf.s1.willfix.Test#setError#(I)V",
"com.google.firebase.perf.network.InstrumentOkHttpEnqueueCallback#onResponse#(Lokhttp3/Call;Lokhttp3/Response;)V"
]
}
```


File renamed without changes.

0 comments on commit ba0ab64

Please sign in to comment.