fix: Android 29, crash on restart and reconn (#10054)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-11-25 21:49:09 +08:00 committed by GitHub
parent 30a11bfe0a
commit d61c99b105
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 40 deletions

View File

@ -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) {
}
}

View File

@ -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()

View File

@ -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()
}