iOS example?

304 views
Skip to first unread message

TruongSinh Tran-Nguyen

unread,
Aug 12, 2019, 11:05:58 AM8/12/19
to Dart FFI
According to closed issue https://github.com/dart-lang/sdk/issues/37224
The VM work is done. Once the decommissioning DBC work lands the FFI will work on iOS automatically. It also will already work in AOT (release/profile builds).

But I haven't been able to see any example of Dart FFI on iOS 

Simon

unread,
Aug 12, 2019, 11:12:39 AM8/12/19
to TruongSinh Tran-Nguyen, Dart FFI
I also saw this and assumed the same but haven't come around to test it out. I expect the same simple test for Android should work on iOS as well if using dev channel.

If you test this out I'd appreciate to hear about the outcome.

--
You received this message because you are subscribed to the Google Groups "Dart FFI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dart-ffi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dart-ffi/73f124cf-bb7a-4542-b785-b21fc56a18f3%40googlegroups.com.

Samir Jindel

unread,
Aug 28, 2019, 4:45:54 AM8/28/19
to Simon, TruongSinh Tran-Nguyen, Dart FFI

Vladimir Djokic

unread,
Sep 15, 2019, 9:53:11 AM9/15/19
to Dart FFI
Hi TruongSinh,

I can't run your example I am getting "Error: Method not found: 'DynamicLibrary.executable'." 
it seems that in flutter version 1.9, method executable is removed? 
 
Do you have some other example ?
Thanks

TruongSinh Tran-Nguyen

unread,
Sep 15, 2019, 8:58:11 PM9/15/19
to Vladimir Djokic, Dart FFI
Hi, it's removed in current stable channel, but re-added in dev and/or master channel (I'm working on another project using master channel, and it's working as of 20 mins ago :D)

--
You received this message because you are subscribed to the Google Groups "Dart FFI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dart-ffi+u...@googlegroups.com.

Vladimir Djokic

unread,
Sep 16, 2019, 3:35:38 AM9/16/19
to Dart FFI
Hey is it really there :-) Thanks!

Also, maybe someone should to update wiki page,  that on iOS we need to set full path for example: DynamicLibrary.open('''Frameworks/my_cpp_lib.framework/my_cpp_lib''').
(On android it is not needed path ,you can use DynamicLibrary.open('''libmy_cpp_lib.so'''))

I have lost the whole day trying to figure out how make it to work:-) 

Thanks again!


On Monday, September 16, 2019 at 2:58:11 AM UTC+2, TruongSinh Tran-Nguyen wrote:
Hi, it's removed in current stable channel, but re-added in dev and/or master channel (I'm working on another project using master channel, and it's working as of 20 mins ago :D)

On Sun, Sep 15, 2019, 20:53 Vladimir Djokic <vladimir...@gmail.com> wrote:
Hi TruongSinh,

I can't run your example I am getting "Error: Method not found: 'DynamicLibrary.executable'." 
it seems that in flutter version 1.9, method executable is removed? 
 
Do you have some other example ?
Thanks

--
You received this message because you are subscribed to the Google Groups "Dart FFI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dart...@googlegroups.com.

Samir Jindel

unread,
Sep 16, 2019, 3:52:30 AM9/16/19
to Vladimir Djokic, Dart FFI
I'm surprised you had to use the full path (DynamicLibrary.open('''Frameworks/my_cpp_lib.framework/my_cpp_lib''')); for me, the Frameworks directory seemed to already be in the linker's path.

We're working to revamp the documentation and add a worked-out example for Android and iOS.

To unsubscribe from this group and stop receiving emails from it, send an email to dart-ffi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dart-ffi/286091ef-3db4-4c74-95b1-93ff5e954ea3%40googlegroups.com.

Craig Jarman

unread,
Sep 16, 2019, 4:06:45 AM9/16/19
to Samir Jindel, Vladimir Djokic, Dart FFI
Looking forward to a worked example.

From a flutter perspective there’s a need for an example Standard project and a package.

I’ve managed to take a C library and wrap it in Java and again in Swift, and the channels, but ideally on would go direct from dart.

Given a plug-in splits into a iOS and Android subset of projects I don’t see the value in a plug-in example.

Thanks




Sent from my iPhone

Samir Jindel

unread,
Sep 20, 2019, 9:38:27 AM9/20/19
to Craig Jarman, Vladimir Djokic, Dart FFI
I've reworked our documentation into a walkthrough: https://github.com/flutter/flutter/wiki/Binding-to-native-code-via-FFI

Does this suit your needs?

Craig Jarman

unread,
Sep 20, 2019, 1:31:38 PM9/20/19
to Samir Jindel, Vladimir Djokic, Dart FFI
Thanks Samir,

I’ve yet to give it a go, will do soon.

One question. For a C-library, I take it that the extern C directive is not required. 

Is the code posted anywhere?An example would be helpful 




Sent from my iPhone

Samir Jindel

unread,
Sep 20, 2019, 2:59:40 PM9/20/19
to Craig Jarman, Vladimir Djokic, Dart FFI
Hi Craig,

The full sample code is not posted anywhere, but the instructions should work "as-is" -- there is nothing hidden or missing.

You don't need to put "extern C" in a C library, only C++ -- it indicates that C++ name mangling should be applied to that symbol.

Regards,
Samir

Craig Jarman

unread,
Sep 22, 2019, 5:24:07 AM9/22/19
to Dart FFI
Can we get the c-library you are calling in the example?

I'm getting the following error:

flutter: Invalid argument(s): Failed to lookup symbol (dlsym(0x1096b2198, nativeadd): symbol not found)

I'm assuming the C code is similar to:

int nativeadd(int a, int b){
   
return a + b;
}



This is based on the examples given at:



Thanks




On Saturday, 21 September 2019 04:59:40 UTC+10, Samir Jindel wrote:
Hi Craig,

The full sample code is not posted anywhere, but the instructions should work "as-is" -- there is nothing hidden or missing.

You don't need to put "extern C" in a C library, only C++ -- it indicates that C++ name mangling should be applied to that symbol.

Regards,
Samir

On Fri, Sep 20, 2019 at 7:31 PM Craig Jarman <craig....@gmail.com> wrote:
Thanks Samir,

I’ve yet to give it a go, will do soon.

One question. For a C-library, I take it that the extern C directive is not required. 

Is the code posted anywhere?An example would be helpful 




Sent from my iPhone

On 20 Sep 2019, at 11:37 pm, Samir Jindel <sji...@google.com> wrote:

I've reworked our documentation into a walkthrough: https://github.com/flutter/flutter/wiki/Binding-to-native-code-via-FFI

Does this suit your needs?

--
You received this message because you are subscribed to the Google Groups "Dart FFI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dart...@googlegroups.com.

Carlos Jiménez Rams

unread,
Sep 24, 2019, 2:55:00 AM9/24/19
to Dart FFI
Thanks Samir, 

I found few issues trying to make sample work, but with easy workaround.
  • Typo in the documentation, you refer to a file android/build.grade, and is obviously android/build.gradle.
  • Android local.properties generated lack of ndk pack, aka ndk.dir=...
  • iOS fails to build due lack of version information at pubspec.yaml, at least on xCode 11
I bet can easy fix this 2 last things on the template generator.

Apart from that, could be possible to use CMake file also for iOS? could be a huge improvement both platforms could be base on same builder.

Thanks for the documentation.

/Carlos

On Friday, September 20, 2019 at 3:38:27 PM UTC+2, Samir Jindel wrote:
I've reworked our documentation into a walkthrough: https://github.com/flutter/flutter/wiki/Binding-to-native-code-via-FFI

Does this suit your needs?

--
You received this message because you are subscribed to the Google Groups "Dart FFI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dart...@googlegroups.com.

Samir Jindel

unread,
Sep 24, 2019, 10:45:23 AM9/24/19
to Carlos Jiménez Rams, Dart FFI, flutter-t...@google.com, Amir Hardon
Apart from that, could be possible to use CMake file also for iOS? could be a huge improvement both platforms could be base on same builder.

 If it is possible, it would be via a feature of CocoaPods. For example, you might be able to accomplish it with: https://guides.cocoapods.org/syntax/podfile.html#pre_install

However, I'm not sure it's a good idea in general. CocoaPods allows the developer to select whether their pods are compiled as Frameworks or statically linked into the main app.
This kind of flexibility is not available in CMake because the CMakeLists.txt specifies how the sources shall be linked.

To unsubscribe from this group and stop receiving emails from it, send an email to dart-ffi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dart-ffi/0bc2ba0d-e4cb-4cd2-a29f-0514bfeb6da5%40googlegroups.com.

Samir Jindel

unread,
Sep 24, 2019, 10:45:52 AM9/24/19
to Carlos Jiménez Rams, Dart FFI, flutter-t...@google.com, Amir Hardon
But, the Flutter tools and plugins teams would know more.

Jenn Magder

unread,
Sep 24, 2019, 1:57:39 PM9/24/19
to Dart FFI
> iOS fails to build due lack of version information at pubspec.yaml, at least on xCode 11

This one should be resolved as of https://github.com/flutter/flutter/pull/40611, which is in v1.10.4.

Samir Jindel

unread,
Sep 24, 2019, 8:32:00 PM9/24/19
to Stuart Morgan, Amir Hardon, Jenn Magder, Collin Jackson, Carlos Jiménez Rams, Dart FFI, flutter-t...@google.com
We have an issue tracking the big picture: https://github.com/flutter/flutter/issues/33227
Let's continue the discussion there.

On Tue, Sep 24, 2019 at 8:03 PM Stuart Morgan <stuart...@google.com> wrote:
I think it would be useful to take a big step back from the specific question about CocoaPods and CMake. If I'm understanding the context of the thread correctly, the basic request here is for clear documentation for best practices, and ideally a preconfigured template in the Flutter tool, for how to incorporate a library into a Flutter project via FFI.

If that's correct, I would say that I don't think the current 'plugin' template is well suited to that, and trying to shoehorn FFI into it is unlikely to be the right approach long term. I would suggest filing a Flutter bug about this (framed in terms of the high-level request above) if there isn't one already, where designs can be discussed and evaluated. The existing dependency build management approaches (e.g., CocoaPods) may or may not be the right tools for that.

-Stuart

On Tue, Sep 24, 2019 at 10:35 AM Amir Hardon <ami...@google.com> wrote:
+Stuart Morgan +Jenn Magder +Collin Jackson (<- Add some CocoaPods knowledge to the thread)
Reply all
Reply to author
Forward
0 new messages