-
Notifications
You must be signed in to change notification settings - Fork 32
Error Testing in Flutter plugin #39
Comments
/cc @dcharkes |
This Medium post mentions a workaround for the symbols not being visible:
Does this workaround work for you? (cc similar issues: flutter/flutter#33227 (comment) and flutter/flutter#33227 (comment).) |
I acutally applied the walkaround in the medium post and only testing for the function which exposed in the dummy Swift function, the library could still not be found. The weird thing is that calling the library in Simualtor is all good, just test is failing. Thanks for mention the #33227 thread, I tried to remove |
@hanwencheng can you describe in which combinations the symbols can and cannot be found? Which combination of options work and doesnt work?
|
Ok, here is the complete testing result: It works on
It failed on
Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, my_function_name): symbol not found)
dart:ffi DynamicLibrary.lookup |
I see. So far, we've been testing by actually running an app on device or emulator/simulator and performing a FFI operations. I will take a look at how unit testing works in Flutter. Do you have a minimal repro that I could easily reproduce? |
I can reproduce this locally.
We need to make |
AFAIK, in React Native it is not possible to directly use a custom native library for unit tests, It would be exciting if it is possible with Dart / Flutter. |
After some more digging:
That's why they do not work together right now. We could possibly make unit tests work for dynamically linked libraries (using That last option, is also what we would need for solving dart-lang/sdk#36712. And then we could generate the right CocoaPods and Maven configs from that. But that is something further out on the horizon. I suggest you use the workaround with |
Now it is totally fine for me to use And I try to understand:
This is the requirement for enabling statically linked libraries in the unit test, it that correct? if it is so, will "supporting dynamically linked libraries in the unit test" be included in the roadmap? |
It also is a requirement for dynamically linked libraries, if the path from the executable to the library is different in the unit test and the deployed app. In the unit test the executable is the It might be possible that dynamically linked libraries already work in unit tests if you |
I have a "better" workaround for this (works on Mac):
|
Closing issue as both |
@derolf thanks for the tip. Unfortunately, passing an absolute path for a Rust shared-library built for Android x86-64 (tried built for Linux x86-64 too) on Ubuntu 20.04 LTS doesn't seem to work. I can confirm that the FFI integration works correctly in the Android app in an Android x86-64 emulator so the tests are the culprit here and @dcharkes the biggest issue here is that
It may seem like a joke but But I might be wrong here and there maybe very good reasons for this. In this case, error messages should probably explain this and maybe provide links for further details. This isn't a luxury and can save time for project maintainers as these details are often forgotten and can waste a lot of a maintainer's time when they work on them or diagnose a related issue. This should be a guiding principle: fail as early as possible and have the code do the checks that can be automated and only require a person to diagnose for cases that can't be handled easily or are likely false positives. And provide rationals (e.g: error messages, docs, code comments) only as a last resort as they often indicate an underlying issue. |
Spent couple of days here wondering why my prebuilt static library did not work on iOS, when on macOS desktop target it worked perfectly. Seems the issue was with dead code stripping, XCode aggressively removing my whole C++ library if there was no calling to in the actual iOS runner code. Added a Bridging header to my iOS Runner project, where I defined one function signature that exists in my C++ library and then called that in a dummy function inside the iOS AppDelegate swift code. This solved the problem! I would have not found this without finding this issue, would be really beneficial if this dead code stripping was mentioned somewhere in the iOS native code section. |
@Sakari369 I remember the dead-code stripping with iOS was mentioned in the docs when I wrote my previous comment. But not sure whether it still exists in the docs right now. But this is only one symptom of the underlying disease of failing many steps too late and making diagnosis exponentially more difficult. |
Okay, yeah to be honest maybe not something Dart should worry about, I was thinking I was on a Flutter issue when I wrote the comment.. But looking at for example https://dart.dev/guides/libraries/objective-c-interop, I can't see any mentions of such things. |
Is it possible to write foreign function test in dart for a flutter plugin?
I use ffi to import rust functions, and they did work in the example application. But failed in the test.
it comes with error:
More Context:
The way I used for calling the library is
For more information, the very simple code base is here
The text was updated successfully, but these errors were encountered: