fix: Android 29, crash on restart and reconn (#10054)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
30a11bfe0a
commit
d61c99b105
@ -32,10 +32,6 @@ import com.hjq.permissions.XXPermissions
|
|||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
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
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +62,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
channelTag
|
channelTag
|
||||||
)
|
)
|
||||||
initFlutterChannel(flutterMethodChannel!!)
|
initFlutterChannel(flutterMethodChannel!!)
|
||||||
flutterEngine.plugins.add(ContextPlugin())
|
|
||||||
thread { setCodecInfo() }
|
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) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ object FFI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
external fun init(ctx: Context)
|
external fun init(ctx: Context)
|
||||||
external fun initContext(ctx: Context)
|
|
||||||
external fun setClipboardManager(clipboardManager: RdClipboardManager)
|
external fun setClipboardManager(clipboardManager: RdClipboardManager)
|
||||||
external fun startServer(app_dir: String, custom_client_config: String)
|
external fun startServer(app_dir: String, custom_client_config: String)
|
||||||
external fun startService()
|
external fun startService()
|
||||||
|
@ -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]
|
#[no_mangle]
|
||||||
pub extern "system" fn Java_ffi_FFI_setClipboardManager(
|
pub extern "system" fn Java_ffi_FFI_setClipboardManager(
|
||||||
env: JNIEnv,
|
env: JNIEnv,
|
||||||
@ -482,12 +470,12 @@ fn init_ndk_context(java_vm: *mut c_void, context_jobject: *mut c_void) {
|
|||||||
*lock = true;
|
*lock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// // https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init
|
// https://cjycode.com/flutter_rust_bridge/guides/how-to/ndk-init
|
||||||
// #[no_mangle]
|
#[no_mangle]
|
||||||
// pub extern "C" fn JNI_OnLoad(vm: jni::JavaVM, res: *mut std::os::raw::c_void) -> jni::sys::jint {
|
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() {
|
if let Ok(env) = vm.get_env() {
|
||||||
// let vm = vm.get_java_vm_pointer() as *mut std::os::raw::c_void;
|
let vm = vm.get_java_vm_pointer() as *mut std::os::raw::c_void;
|
||||||
// init_ndk_context(vm, res);
|
init_ndk_context(vm, res);
|
||||||
// }
|
}
|
||||||
// jni::JNIVersion::V6.into()
|
jni::JNIVersion::V6.into()
|
||||||
// }
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user