From 062c6b87cac3d2ea7cf70bd471e13fa335841843 Mon Sep 17 00:00:00 2001 From: ChinaLike <572919350@qq.com> Date: Wed, 17 Apr 2024 16:54:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E3=80=8C=E8=A7=A3=E5=86=B3=E6=B7=B7?= =?UTF-8?q?=E6=B7=86=E5=90=8EJSON=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 10 +++-- app/proguard-rules.pro | 6 +++ .../jsbridge/bridge/CustomJavascriptBridge.kt | 37 ++++++++++--------- testGroup/build.gradle | 7 +++- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e9152a4..86c249a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } } @@ -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' @@ -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" } \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f1b4245..75cb975 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -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.** { *; } + diff --git a/app/src/main/java/com/like/jsbridge/bridge/CustomJavascriptBridge.kt b/app/src/main/java/com/like/jsbridge/bridge/CustomJavascriptBridge.kt index e93b5cc..c8cacca 100644 --- a/app/src/main/java/com/like/jsbridge/bridge/CustomJavascriptBridge.kt +++ b/app/src/main/java/com/like/jsbridge/bridge/CustomJavascriptBridge.kt @@ -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 @@ -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) @@ -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") diff --git a/testGroup/build.gradle b/testGroup/build.gradle index 508d36b..bb6069f 100644 --- a/testGroup/build.gradle +++ b/testGroup/build.gradle @@ -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' } \ No newline at end of file