Skip to content

Commit 062c6b8

Browse files
committed
feat:「解决混淆后JSON无法解析实体类」
1 parent 2a75ed1 commit 062c6b8

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ android {
1919

2020
buildTypes {
2121
debug {
22-
minifyEnabled false
22+
minifyEnabled true
2323
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2424
}
2525
release {
26-
minifyEnabled false
26+
minifyEnabled true
2727
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2828
}
2929
}
@@ -50,7 +50,6 @@ dependencies {
5050
implementation 'androidx.appcompat:appcompat:1.2.0'
5151
implementation 'com.google.android.material:material:1.2.1'
5252
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
53-
implementation project(path: ':jsbridge')
5453
implementation project(path: ':testGroup')
5554
testImplementation 'junit:junit:4.+'
5655
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
@@ -62,7 +61,10 @@ dependencies {
6261
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
6362
implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'
6463

65-
kapt project(':jsbridge-compiler')
64+
// implementation project(path: ':jsbridge')
65+
// kapt project(':jsbridge-compiler')
66+
implementation 'com.github.ChinaLike.JsBridge:jsbridge:0.1.1'
67+
kapt 'com.github.ChinaLike.JsBridge:jsbridge-compiler:0.1.1'
6668

6769
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
6870
}

app/proguard-rules.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22+
23+
-keep class com.like.jsbridge.CustomBean {*;}
24+
-keep class kotlin.** { *; }
25+
26+
-keep class org.jetbrains.** { *; }
27+

app/src/main/java/com/like/jsbridge/bridge/CustomJavascriptBridge.kt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Context
55
import android.content.DialogInterface
66
import android.content.res.Resources
77
import android.os.Handler
8+
import android.util.Log
89
import android.webkit.JavascriptInterface
910
import android.widget.Toast
1011
import com.alibaba.fastjson.JSON
@@ -21,52 +22,52 @@ import com.like.jsbridge.CustomBean
2122
@JavascriptBridge("custom")
2223
class CustomJavascriptBridge(private val context: Context) {
2324
@JavascriptInterface
24-
fun nativeNoArgAndNoCallback(){
25-
Toast.makeText(context,"调用原生无参数无回调方法",Toast.LENGTH_SHORT).show()
25+
fun nativeNoArgAndNoCallback() {
26+
Toast.makeText(context, "调用原生无参数无回调方法", Toast.LENGTH_SHORT).show()
2627
}
2728

2829
@JavascriptInterface
29-
fun nativeNoArgAndCallback(callback: Callback){
30+
fun nativeNoArgAndCallback(callback: Callback) {
3031
callback.success("成功回调")
3132
}
3233

3334
@JavascriptInterface
34-
fun nativeArgAndNoCallback(params:String){
35-
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
35+
fun nativeArgAndNoCallback(params: String) {
36+
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
3637
}
3738

3839
@JavascriptInterface
39-
fun nativeArgAndCallback(params:String,callback: Callback){
40-
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
40+
fun nativeArgAndCallback(params: String, callback: Callback) {
41+
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
4142
callback.success("成功回调")
4243
}
4344

4445
@JavascriptInterface
45-
fun nativeDeleteCallback(params:String,callback: Callback){
46-
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
46+
fun nativeDeleteCallback(params: String, callback: Callback) {
47+
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
4748
callback.success(true)
4849
Handler().postDelayed(Runnable {
49-
callback.callback(1,"失败",null)
50-
},3000)
50+
callback.callback(1, "失败", null)
51+
}, 3000)
5152
}
5253

5354
@JavascriptInterface
54-
fun nativeNoDeleteCallback(params:String,callback: Callback){
55-
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
55+
fun nativeNoDeleteCallback(params: String, callback: Callback) {
56+
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
5657
callback.success(false)
5758
Handler().postDelayed(Runnable {
58-
callback.callback(1,"失败",null)
59-
},3000)
59+
callback.callback(1, "失败", null)
60+
}, 3000)
6061
}
6162

6263
@JavascriptInterface
63-
fun nativeSyncCallback():String{
64+
fun nativeSyncCallback(): String {
6465
return "原生同步回调"
6566
}
6667

6768
@JavascriptInterface
6869
fun nativeDialog(params: String?, successCallback: Callback, failCallback: Callback) {
69-
val bean = JSON.parseObject(params,CustomBean::class.java)
70+
val bean = JSON.parseObject(params, CustomBean::class.java)
7071
AlertDialog.Builder(context)
7172
.setTitle(bean.title)
7273
.setMessage(bean.content)
@@ -86,7 +87,7 @@ class CustomJavascriptBridge(private val context: Context) {
8687
}
8788

8889
@JavascriptInterface
89-
fun statusHeight():Int{
90+
fun statusHeight(): Int {
9091
var result = 0
9192
val resourceId = context.resources
9293
.getIdentifier("status_bar_height", "dimen", "android")

testGroup/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ dependencies {
3939
implementation 'androidx.appcompat:appcompat:1.2.0'
4040
implementation 'com.google.android.material:material:1.2.1'
4141
implementation 'com.alibaba:fastjson:1.1.72.android'
42-
implementation project(':jsbridge-annotation')
43-
kapt project(':jsbridge-compiler')
42+
// implementation project(':jsbridge-annotation')
43+
// kapt project(':jsbridge-compiler')
44+
45+
implementation 'com.github.ChinaLike.JsBridge:jsbridge:0.1.1'
46+
kapt 'com.github.ChinaLike.JsBridge:jsbridge-compiler:0.1.1'
4447
}

0 commit comments

Comments
 (0)