ivnsch / rust_android_ios

Android / iOS app with shared Rust logic
240 stars 21 forks source link

Flutter #7

Open lattice0 opened 3 years ago

lattice0 commented 3 years ago

I've been designing a Rust library for usage with Flutter. I see that you're doing Kotlin/Java <-> Rust here, but you mention Flutter.

Is there a plan to make a template for Flutter? Because there are 2 methods to consider: FFI vs Plugin call. Since plugin calls are very slow, FFI should be prefered, but what to do when Rust needs JNI objects? You can't pass them through Flutter's FFI

ivnsch commented 2 years ago

There are other repos with Flutter templates (which you probably have found by now). I don't see a need to make another one.

Just to clarify, why would Rust need JNI objects when using (C based) FFI? As far I understand, with Flutter you use C FFI for everything, so you don't have to touch JNI at all.

Sorry for the late reply, for some reason I was not subscribed to all the notifications and didn't see this.

lattice0 commented 2 years ago

There are other repos with Flutter templates (which you probably have found by now). I don't see a need to make another one.

Just to clarify, why would Rust need JNI objects when using (C based) FFI? As far I understand, with Flutter you use C FFI for everything, so you don't have to touch JNI at all.

Sorry for the late reply, for some reason I was not subscribed to all the notifications and didn't see this.

Sometimes you need to call C code through plugin calls through JNI. For example, getting a C pointer to an opengl renderer so I can pass to the Rust library via FFI

ivnsch commented 2 years ago

I'd solve this kind of situation at library level, i.e. the native (Android in this case) library used in the plugin would have a dedicated Rust binary with the JNI bindings. It would be invisible at plugin/Flutter level.