Skip to content

Commit

Permalink
gralde到v0.14+, 添加混淆配置, 防混淆代码变更
Browse files Browse the repository at this point in the history
  • Loading branch information
pedant committed Nov 6, 2014
1 parent 79642a8 commit a8b0231
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,22 @@ Java层方法可以返回void 或 能转为字符串的类型(如int、long、
}

### 发布时防混淆
注意注入类中的方法名称不能被混淆,否则页面会调用失败。故发布时需在你的混淆配置文件中加入注入类的防混淆代码,如demo中的HostJsScope配置:

-keepclassmembers class cn.pedant.SafeWebViewBridge.demo.HostJsScope{ *; }
发布时需在你的混淆配置加入像下面这样的代码,注意**返回到页面的自定义Java类以及注入到页面的接口类都要换成你项目中使用实际类名**:

##--------------- BEGIN: Gson防混淆 ----------
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.idea.fifaalarmclock.entity.***
-keep class com.google.gson.stream.** { *; }
##--------------- END ----------

##--------------- BEGIN: 返回到页面的自定义Java对象防混淆 ----------
-keepclassmembers class cn.pedant.SafeWebViewBridge.sample.HostJsScope$RetJavaObj{ *; }
##--------------- END ----------

##--------------- BEGIN: 注入到页面的接口类防混淆 ----------
-keepclassmembers class cn.pedant.SafeWebViewBridge.sample.HostJsScope{ *; }
##--------------- END ----------

### 小心过大数字
JS中使用过大数字时,可能会导致精度丢失或者错误的数字结果,如下面:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
classpath 'com.android.tools.build:gradle:0.14.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public String call(WebView webView, String jsonStr) {

// 方法匹配失败
if (currMethod == null) {
return getReturn(jsonStr, 500, "not found method(" + methodName + ") with valid parameters");
return getReturn(jsonStr, 500, "not found method(" + sign + ") with valid parameters");
}
// 数字类型细分匹配
if (numIndex > 0) {
Expand Down
8 changes: 8 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ android {
lintOptions {
abortOnError false
}

buildTypes {
release {
proguardFile 'proguard-android.txt'
minifyEnabled true
shrinkResources true
}
}
}

dependencies {
Expand Down

0 comments on commit a8b0231

Please sign in to comment.