diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt index 15dee6002f57..333ea9f14bd2 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt @@ -32,10 +32,6 @@ import com.hjq.permissions.XXPermissions import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.MethodChannel -import io.flutter.embedding.engine.plugins.FlutterPlugin -import io.flutter.plugin.common.MethodCall -import io.flutter.plugin.common.MethodChannel.MethodCallHandler -import io.flutter.plugin.common.MethodChannel.Result import kotlin.concurrent.thread @@ -66,7 +62,6 @@ class MainActivity : FlutterActivity() { channelTag ) initFlutterChannel(flutterMethodChannel!!) - flutterEngine.plugins.add(ContextPlugin()) thread { setCodecInfo() } } @@ -417,16 +412,3 @@ class MainActivity : FlutterActivity() { } } } - -// https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init -class ContextPlugin : FlutterPlugin, MethodCallHandler { - override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { - FFI.initContext(flutterPluginBinding.applicationContext) - } - override fun onMethodCall(call: MethodCall, result: Result) { - result.notImplemented() - } - - override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { - } -} \ No newline at end of file diff --git a/flutter/android/app/src/main/kotlin/ffi.kt b/flutter/android/app/src/main/kotlin/ffi.kt index 653465782b3c..69b395ac2e9d 100644 --- a/flutter/android/app/src/main/kotlin/ffi.kt +++ b/flutter/android/app/src/main/kotlin/ffi.kt @@ -13,7 +13,6 @@ object FFI { } external fun init(ctx: Context) - external fun initContext(ctx: Context) external fun setClipboardManager(clipboardManager: RdClipboardManager) external fun startServer(app_dir: String, custom_client_config: String) external fun startService() diff --git a/libs/scrap/src/android/ffi.rs b/libs/scrap/src/android/ffi.rs index 0e48f60e6f72..ffa38a965d73 100644 --- a/libs/scrap/src/android/ffi.rs +++ b/libs/scrap/src/android/ffi.rs @@ -205,18 +205,6 @@ pub extern "system" fn Java_ffi_FFI_init(env: JNIEnv, _class: JClass, ctx: JObje } } -#[no_mangle] -pub extern "system" fn Java_ffi_FFI_initContext(env: JNIEnv, _class: JClass, ctx: JObject) { - log::debug!("MainActivity initContext from java"); - if let Ok(jvm) = env.get_java_vm() { - if let Ok(context) = env.new_global_ref(ctx) { - let java_vm = jvm.get_java_vm_pointer() as *mut c_void; - let context_jobject = context.as_obj().as_raw() as *mut c_void; - init_ndk_context(java_vm, context_jobject); - } - } -} - #[no_mangle] pub extern "system" fn Java_ffi_FFI_setClipboardManager( env: JNIEnv, @@ -482,12 +470,12 @@ fn init_ndk_context(java_vm: *mut c_void, context_jobject: *mut c_void) { *lock = true; } -// // https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init -// #[no_mangle] -// pub extern "C" fn JNI_OnLoad(vm: jni::JavaVM, res: *mut std::os::raw::c_void) -> jni::sys::jint { -// if let Ok(env) = vm.get_env() { -// let vm = vm.get_java_vm_pointer() as *mut std::os::raw::c_void; -// init_ndk_context(vm, res); -// } -// jni::JNIVersion::V6.into() -// } +// https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init +#[no_mangle] +pub extern "C" fn JNI_OnLoad(vm: jni::JavaVM, res: *mut std::os::raw::c_void) -> jni::sys::jint { + if let Ok(env) = vm.get_env() { + let vm = vm.get_java_vm_pointer() as *mut std::os::raw::c_void; + init_ndk_context(vm, res); + } + jni::JNIVersion::V6.into() +}