Skip to content

Support integrating with C/C++ in plugin framework #7053

Closed
@jtrunick

Description

@jtrunick

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

Activity

chinmaygarde

chinmaygarde commented on Nov 30, 2016

@chinmaygarde
Member

@jason-simmons knows the most about Gradle. Once we have an .so, I can definitely help getting it loaded.

jtrunick

jtrunick commented on Dec 2, 2016

@jtrunick
Author

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

eseidelGoogle commented on Dec 6, 2016

@eseidelGoogle
Contributor

Presumably we would also need to add a C API for sending HostMessages from C/C++ code to Dart.

jtrunick

jtrunick commented on Dec 6, 2016

@jtrunick
Author

Yes please. I have a suspicion that the C->Java callback may not be cheap.

changed the title [-]C/C++ Example[/-] [+]Support integrating with C/C++ in plugin framework[/+] on Feb 2, 2017
added this to the 4: Make shippers happy milestone on Feb 2, 2017
ijustlovemath

ijustlovemath commented on May 20, 2017

@ijustlovemath

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

eseidelGoogle commented on May 21, 2017

@eseidelGoogle
Contributor

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

timotheecour commented on Sep 20, 2017

@timotheecour

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

mehmetf commented on Oct 2, 2017

@mehmetf
Contributor

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

Hixie commented on Oct 2, 2017

@Hixie
Contributor

One such app wrote their own C++ libraries for operating the camera to reduce latency. [...] Forcing them to go through PlatformChannel + JNI will not achieve that on Android.

What was their solution on Android for getting from C++ to Java and back?

229 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: new featureNothing broken; request for a new capabilitydependency: dartDart team may need to help usengineflutter/engine repository. See also e: labels.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specifically

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @chinmaygarde@atsushieno@brianegan@mraleph@tofutim

      Issue actions

        Support integrating with C/C++ in plugin framework · Issue #7053 · flutter/flutter