Closed
Description
It would be nice to have an example of calling C/C++ code, or at least how to build native code along with a Flutter app. This may purely a Gradle question, but its not clear to someone that's not an expert on Gradle (for example, me), how to pull this off.
Admin comment: Please see dart-lang/sdk#34452 for current status and additional information
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
chinmaygarde commentedon Nov 30, 2016
@jason-simmons knows the most about Gradle. Once we have an .so, I can definitely help getting it loaded.
jtrunick commentedon Dec 2, 2016
I did find that under buildSrc there is another property for setting the gradle build version. After updating to 2.2.2 I've progressed, and was able to verify the .so loads, and is callable from Java.
eseidelGoogle commentedon Dec 6, 2016
Presumably we would also need to add a C API for sending HostMessages from C/C++ code to Dart.
jtrunick commentedon Dec 6, 2016
Yes please. I have a suspicion that the C->Java callback may not be cheap.
[-]C/C++ Example[/-][+]Support integrating with C/C++ in plugin framework[/+]ijustlovemath commentedon May 20, 2017
Any update on this? Considering Flutter for building a cross platform app that calls C++ code compiled into a shared library, and this is the only major stopping point.
eseidelGoogle commentedon May 21, 2017
This is possible today (and @jtrunick did so in his shipping app), but you have to bounce through Java or Obj-C first.
i.e. you can use https://flutter.io/platform-channels/ to talk from Dart to Obj-C/Java and then from Obj-C/Java call into your C++ code. This bug covers adding more direct support for this, and potentially avoiding the Obj-C/Java passthrough.
timotheecour commentedon Sep 20, 2017
Since Dart VM is implemented in C++ shouldn't there be an easier (if less safe) way to call C shared libraries directly (say via dlopen) ? How much change would be required for basic (unsafe/experimental) support?
Is something like this: https://www.dartlang.org/articles/dart-vm/native-extensions available on android or ios?
mehmetf commentedon Oct 2, 2017
We have heard this requirement from a couple of Google apps:
One such app wrote their own C++ libraries for operating the camera to reduce latency. These libraries are platform specific and optimized to work as quickly as possible. Invoking these libraries with the lowest possible latency is critical for such apps. Forcing them to go through PlatformChannel + JNI will not achieve that on Android.
There are advanced mobile teams out there who write business logic components in C++ to be able to share it between their Android and iOS implementations. Flutter supporting direct integration with those libraries would further cement its position of being the best cross-platform framework out there.
I don't think this is a must have. However, this is one area that Flutter can further differentiate itself from other cross-platform solutions.
Hixie commentedon Oct 2, 2017
What was their solution on Android for getting from C++ to Java and back?
229 remaining items