-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using @Native/@FfiNative in an FFI plugin on Android #923
Comments
OK, I found that as far as Unfortunately though the reason I'm using If, for example, I have a native
So I have to figure out how to make that request without having this behavior and have the global symbols as per goal. Indeed, I would like to be able to retrieve them by declaring native functions with
But this only works if the symbols in the library are global. Considering what I've read it would seem that Linux and Android (among other systems) differ on this loading aspect because Android would load dynamic libraries using And it is probably for this reason that in this comment a test made with Linux is proposed which works and after having used I would also like to find a way to put the received handle from It seems to me that in this comment this was proposed. SDK: Flutter 3.7.3 • stable channel • Dart 2.19.2 |
Considering that in the same Andorid folder of the libraries, in addition to the custom native library If I could initialize the custom library with flutter's one the problem would be skipped. |
I believe dlopen just wants the dynamic library name on Android, not the path. The dynamic library should be bundled in the the final app in the folder where dlopen will look for it. If you have problems bundling, please try to use |
I started the tests using the library name without path with I tried now again with no path but the result is the same. I only get the correct handle without using The library is found both by In the end the difference with and without path is reduced to the fact that in the first case |
So... Thanks again for your availability I believe I have indicated in a precise manner what I want to obtain and patiently all the operations carried out and explained reasoning about them but it may not be clear yet, maybe because of English which is not my language. Creating a Dart project for using the ffi library using templates is certainly useful if you don't already have a basis to start from, which in this case I already have, and unless I'm mistaken there isn't much to it. In particular:
I miss something? Yes. Does it help me to use flutter I've decided to paste all my files here so if anyone wants to use them as a test bed and figure out how to use
That's all. Thank you. |
I didn't mean to use that to not use Using the
Is there a particular reason
This is problematic, because of the bundling. Your Flutter apps will not have the dynamic libraries inside the final app bundle unless you start modifying the build files manually (Gradle for Android). This is why we have the template. flutter/flutter#129757 should make it more feasible to just tell that you have a dynamic library and then Flutter will take care of bundling it. |
OK, thanks anyway for that.
I understand and I agree that the template makes things easier, BUT, apart from that I always like to do the most complicated things, after having seen (days before your advice) that that solution didn't bring any advantage to what I wanted to do so I discarded it and as I said above, also pasting the piece of code, I have already modified the build.gradle file and the libraries are correctly in place for each ABI. I haven't done a release version and I'm in debug and unless that makes a difference the external library is there. Instead of why IF it was NOT present:
I also paste a screenshot to show that the library exists. In another post I also pointed out that it was together with
Let's recap.
But of course there is! :-)
OK, wait! This is all I want! A river of writings for nothing!? So, how? Please! |
We run tests with this hack on our unit tests on the Dart CI. For example this test is using the workaround on Android devices: https://dart-current-results.web.app/#/filter=ffi/function_structs_by_value_generated_ret_native_test&showAll. I'll take some time to apply my own suggestions to
Agreed, |
OK, I've seen it and it's interesting. |
I don't have access to an arm 32 bit device. Your armabi-v7 indicates you're targeting 32 bit arm. For arm64 for it works for me on a physical device, but not on an emulator. See my example project here: https://github.com/dcharkes/ffi-plugin-with-ffi-native Could you try to run it on your arm32 device? |
To tell the truth, I have indicated armabi-v7 only as an example because, as I said, the library is generated for each ABI, but it is true that when I build the test APKs, I use that to try them on my smartphone. As soon as my programming session is over, I'll do a test with your project and thank you for now. PS: But if it doesn't work for you with the emulator, which is perhaps the same problem I'm having, how can your test environment be successful if there certainly won't be any physical devices connected? :-| |
Update on what I've done about it. Since @dcharkes reported that he wasn't successful using the emulator first I stopped using mine and switched to the physical ARM64 device (although that's quite a bummer for someone who is developing and is in a stage where he's just debugging regardless of performance).
Inside a folder dedicated to tests I launched the command Although not essential I renamed the I then took the In the root level
In the
In In In And since I was writing from memory I think that's all. So, having done this and starting in debug mode with the physical device connected, it worked BUT with some quirks that make the difference in the reasoning made up to now. In practice, using the path indicated above or indicating only the library name without path I always get the handle with the address and see the symbols in And to demonstrate that it seems superfluous I add that it also works by removing And to confirm that all this is useless I add that you can also remove Conclusions The fact that the handle was received zeroed with Android is derived from the emulator since it is useless to load the libraries by hand and it would seem that everything depends on something (which I still have to look for) that differentiates the template from the configuration file I was trying to using me (although I thought I had replicated everything needed). As soon as I find it, I'll let you know. |
I'm struggling with declaring and loading native libraries but something is wrong on Android.
Library load function with
DynamicLibrary.open
with which there are no problems.Library load function with dlopen native function that there are problems with.
No errors but the handle has an empty pointer and is not usable to use symbols of the library.
Types of declarations used in different tests without success (in addition to others).
Same thing also for function release with dlclose native function.
Types of declarations used in different tests without success (in addition to others).
I have to be able to use the
@FfiNative
andexternal
declaration, but since I couldn't I also tried with lookup noting that it doesn't change anything.If it serves as information and if it impacts the flow, programming in C
dlopen
works fine in my system (after fixing it because thedlfcn.c
anddlfcn.h
files were missing).So, why?
SDK: Flutter 3.7.3 • stable channel • Dart 2.19.2
Workspace: Flutter
Target platform: Android
Environment OS: Windows 10
The text was updated successfully, but these errors were encountered: