Skip to content

Commit

Permalink
feat:「解决混淆后JSON无法解析实体类」
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinaLike committed Apr 17, 2024
1 parent 2a75ed1 commit 062c6b8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
10 changes: 6 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ android {

buildTypes {
debug {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -50,7 +50,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(path: ':jsbridge')
implementation project(path: ':testGroup')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand All @@ -62,7 +61,10 @@ dependencies {
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'

kapt project(':jsbridge-compiler')
// implementation project(path: ':jsbridge')
// kapt project(':jsbridge-compiler')
implementation 'com.github.ChinaLike.JsBridge:jsbridge:0.1.1'
kapt 'com.github.ChinaLike.JsBridge:jsbridge-compiler:0.1.1'

implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}
6 changes: 6 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class com.like.jsbridge.CustomBean {*;}
-keep class kotlin.** { *; }

-keep class org.jetbrains.** { *; }

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.DialogInterface
import android.content.res.Resources
import android.os.Handler
import android.util.Log
import android.webkit.JavascriptInterface
import android.widget.Toast
import com.alibaba.fastjson.JSON
Expand All @@ -21,52 +22,52 @@ import com.like.jsbridge.CustomBean
@JavascriptBridge("custom")
class CustomJavascriptBridge(private val context: Context) {
@JavascriptInterface
fun nativeNoArgAndNoCallback(){
Toast.makeText(context,"调用原生无参数无回调方法",Toast.LENGTH_SHORT).show()
fun nativeNoArgAndNoCallback() {
Toast.makeText(context, "调用原生无参数无回调方法", Toast.LENGTH_SHORT).show()
}

@JavascriptInterface
fun nativeNoArgAndCallback(callback: Callback){
fun nativeNoArgAndCallback(callback: Callback) {
callback.success("成功回调")
}

@JavascriptInterface
fun nativeArgAndNoCallback(params:String){
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
fun nativeArgAndNoCallback(params: String) {
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
}

@JavascriptInterface
fun nativeArgAndCallback(params:String,callback: Callback){
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
fun nativeArgAndCallback(params: String, callback: Callback) {
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
callback.success("成功回调")
}

@JavascriptInterface
fun nativeDeleteCallback(params:String,callback: Callback){
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
fun nativeDeleteCallback(params: String, callback: Callback) {
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
callback.success(true)
Handler().postDelayed(Runnable {
callback.callback(1,"失败",null)
},3000)
callback.callback(1, "失败", null)
}, 3000)
}

@JavascriptInterface
fun nativeNoDeleteCallback(params:String,callback: Callback){
Toast.makeText(context,params,Toast.LENGTH_SHORT).show()
fun nativeNoDeleteCallback(params: String, callback: Callback) {
Toast.makeText(context, params, Toast.LENGTH_SHORT).show()
callback.success(false)
Handler().postDelayed(Runnable {
callback.callback(1,"失败",null)
},3000)
callback.callback(1, "失败", null)
}, 3000)
}

@JavascriptInterface
fun nativeSyncCallback():String{
fun nativeSyncCallback(): String {
return "原生同步回调"
}

@JavascriptInterface
fun nativeDialog(params: String?, successCallback: Callback, failCallback: Callback) {
val bean = JSON.parseObject(params,CustomBean::class.java)
val bean = JSON.parseObject(params, CustomBean::class.java)
AlertDialog.Builder(context)
.setTitle(bean.title)
.setMessage(bean.content)
Expand All @@ -86,7 +87,7 @@ class CustomJavascriptBridge(private val context: Context) {
}

@JavascriptInterface
fun statusHeight():Int{
fun statusHeight(): Int {
var result = 0
val resourceId = context.resources
.getIdentifier("status_bar_height", "dimen", "android")
Expand Down
7 changes: 5 additions & 2 deletions testGroup/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.alibaba:fastjson:1.1.72.android'
implementation project(':jsbridge-annotation')
kapt project(':jsbridge-compiler')
// implementation project(':jsbridge-annotation')
// kapt project(':jsbridge-compiler')

implementation 'com.github.ChinaLike.JsBridge:jsbridge:0.1.1'
kapt 'com.github.ChinaLike.JsBridge:jsbridge-compiler:0.1.1'
}

0 comments on commit 062c6b8

Please sign in to comment.