flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.93k stars 27.4k forks source link

Support golang (e.g. gomobile) integration with Flutter #65315

Closed elansys-kc closed 2 months ago

elansys-kc commented 4 years ago

Use case

As the following article concluded in 2018. It would be nice if flutter had better gomobile integration.

Building a mobile frontend for a Go application using Flutter.

This is a more recent shorter article that unfortunately misses out some details like filenames. Meet the coolest tech marriage: Flutter & Go!

Slides: Flutter + Gomobile

Proposal

Ideally better integration of the gomobile tool or alternatively a maintained article possibly based on the one above that is easily found alongside the C interop on flutter.dev. This would help developers more easily build apps with a greater depth of packages that are memory safe, easier to write and have even better multicore capabilities than C provides. This should bolster the takeup of Flutter further.

Please thumbs up, if you do or would like to use golang in your flutter project(s)?

stuartmorgan commented 4 years ago

better integration of the gomobile tool

Can you explain what advantage you see to gomobile now that FFI is available?

elansys-kc commented 4 years ago

gomobile produces an .aar with Kotlin and/or swift bindings by default but can also produce java and obj-c bindings. I believe this approach uses only memory safe code. I am new to the Android side and although I am a c programmer I primarily came to flutter for it's web support.

Ideally, I would like guidance as to the recommended approach, perhaps with reasoning. Rather than every Go developer having to work it out or even worse, grabbing c libs as an easier documented approach.

If Dart:FFI is the recommended approach then specific guidance as to how to do so for Go would be useful.

However, when I have looked at Dart:FFI and seen unsafe being in use, pulling the c compiler into play and voiding the memory safety guarantee, it has made me look to gomobile or binary execution (perhaps without significant reason as perhaps the c is simply glue code, but I suspect this to be a significant disadvantage compared to the gomobile approach, either in safety or portability).

For those considering binary execution: I expected building native go binaries for android and other platforms and executing them as an asset might be the simplest approach (commandline arguments and optional http server for desktop able to share functions). Documentation on bundling an asset inside the apk (API > 28 compaibility) to be executable by something like process.run, would be very welcome. However it looks like cross-compiling for Darwin may require a c compiler in any case and whilst binaries built for Linux do not and may run well, the issues are not clear (likely go DNS instead of Android DNS with private DNS support by default due to no resolv.conf etc.). Target android also appears to require a c compiler, whereas building upon an Android device itself does not.

pedromassangocode commented 4 years ago

Not sure if this should be considered new feature or better document Flutter, so I will just label it proposal for now. Please feel free to add other labels.

elansys-kc commented 4 years ago

https://github.com/go-flutter-desktop/go-flutter/issues/334

elansys-kc commented 4 years ago

https://github.com/jerson/flutter-openpgp/issues/7

This issue mentions sticking with gomobile, but I don't understand the reason. I assume gomobile handles architecture matters under the hood with swift/kotlin etc.:

Quote: "looks like ffi dont work well for mobile because i need to get the architecture in dart and i think gomobile is enough for that but in the future when ffi had a better implementation easly could be used to replace gomobile"

elansys-kc commented 4 years ago

This package shows how one might use Dart: FFI for golang. I can't say that I understand the details but without guidance, I plan to utilise the gomobile option as I expect it has already solved some C cross-platform compilation issues and additionally is more cross platform than e.g. xgo and Docker that are mentioned on the packages link (Docker does not run on OpenBSD for example, for when Dart arrives on OpenBSD).

dexecve

Quote: "You may want to cross compile the library for multiple platforms. Cross compilation of a static golang binary is relatively straight forward these days however it's not as easy to cross compile a library as cgo is required which normally is disabled for cross compilation.

I have found xgo very helpful for this."

Hixie commented 4 years ago

I don't expect this is something we will have time to get to soon, but it's worth tracking. We certainly would be happy to advise if this is something that someone would like to champion.

elansys-kc commented 4 years ago

Ok, Actually I prefer the smaller amount of boiler plate with the FFI approach. Maybe someone will come up with a better way of integrating gomobile at some time in the future or the android compiler may catch up to the desktop support in cross platform simplicity.

Seems less problematic to reduce the functionality of our mobile app for now compared to the flutter for web/electron (more platforms) and native desktop versions if/when released. Thanks

elansys-kc commented 4 years ago

Turns out that truly cross platform offline compatible security (Javascript for Open Source BSDs etc.) was problematic without Go, in any case even if resorting to manual web crypto. So the mobile app will be delayed until we work out the best way forward, maintenance wise.

jerson commented 4 years ago

hi @elansys-kc may this could help, recently I released a new version of a flutter library using Go with FFI without gomobile

Flutter: https://github.com/jerson/flutter-openpgp/tree/v1.0.0-rc1

Go: https://github.com/jerson/openpgp-mobile/tree/v0.9.1

gargakshit commented 3 years ago

Any updates on this?

prologic commented 2 years ago

@jerson Are you able to document how you went about creating this Flutter+Go library?

jonahwilliams commented 2 months ago

We're not planning to add any built in support for additional languages, but should be possible to use go via method/message channels

github-actions[bot] commented 1 month ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.