Open gzjaychen opened 3 years ago
Hi @gzjaychen
Can you please provide your flutter doctor -v
your flutter run --verbose
and a complete reproducible minimal code sample in a GitHub repository
Thank you
Thank you for your reply. Here‘s the info you need.
flutter doctor -v
[✓] Flutter (Channel stable, 1.22.3, on Mac OS X 10.15.6 19G2021, locale zh-Hans-CN)
• Flutter version 1.22.3 at /Users/chenjiangfeng/dev_tool/flutter_sdk/flutter_macos_1.22.3-stable
• Framework revision 8874f21e79 (5 days ago), 2020-10-29 14:14:35 -0700
• Engine revision a1440ca392
• Dart version 2.10.3
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/chenjiangfeng/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = /Users/chenjiangfeng/Library/Android/sdk
• Java binary at: /Applications/Android Studio 4.1.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.1, Build version 12A7403
• CocoaPods version 1.9.3
[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio 4.1.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[!] IntelliJ IDEA Community Edition (version 2020.2.3)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins
[✓] VS Code (version 1.50.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.16.0
[✓] Connected device (1 available)
• iPhone 12 Pro Max (mobile) • 00B9F33D-BD5A-48CA-85EB-D6702369FC0B • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-1 (simulator)
! Doctor found issues in 2 categories.
✗ Flutter plugin not installed
✗ Dart plugin not installed
I have already installed these plugins, and they work well. I don't know why these errors happen. And I think we can ignore these.
https://github.com/gzjaychen/native_add
flutter run --verbose:
comment is too long to commit. https://drive.google.com/file/d/1rl5g8ZGq3nTK-_DiTOc8O-s9nuWh0wyX/view?usp=sharing Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, native_add): symbol not found)
The dlsym
call is failing which means the templates (or user code) tried to lookup native symbols in a library that does not exist.
cc @jmagman
nm Runner.app/Runner
shows the Objective-C symbols but not the fii function:
00000001000070f0 t -[NativeAddPlugin handleMethodCall:result:]
I can can muck up the linker flags to not include -l"native_add"
and it doesn't include the Objective-CNativeAddPlugin
symbols. Which means it's actually linking the static lib. Library search paths are correct.
I changed the function name to native_adder
to pick out just the C function, and I do see it in the static lib:
nm libnative_add.a
...
0000000000000000 T _native_adder
When I directly link the app target on libnative_add.a
to bypass the CocoaPods stuff, it's the same behavior. Though maybe that's a red herring? Anyway it still crashes.
It works when I use dylibs (use_frameworks!
in the Podfile).
And it also works on the dart side when I first declare and call it in the app itself:
int32_t native_adder(int32_t x, int32_t y);
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
native_adder(1,2);
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
I can try bisecting, but I think someone who knows more about what DynamicLibrary.process()
is doing should take a look.
@sjindel-google Do you know the last time this worked? Is there an integration test running somewhere?
@sjindel-google Can you take a moment to look at this problem? Please, thank you.
This issue is reproducible on the latest stable
and master
channels with sample code at https://github.com/flutter/flutter/issues/69559#issuecomment-721080779.
Similar issue on dart-lang/ffi repository: https://github.com/dart-lang/native/issues/897
cc @dcharkes maybe someone working on ffi tooling wants to take a look.
I'm a bit confused what this issue is about:
flutter create -a java -i objc --platforms=android,ios --template=plugin native_add
This does not use the plugin_ffi
or package_ffi
template.
The documentation on https://docs.flutter.dev/platform-integration/macos/c-interop is outdated. Devs should be using one of the new templates for FFI development. (This issue and the documentation are from before those templates existed.) I can take a look at updating this documenation.
https://flutter.dev/docs/development/platform-integration/c-interop 1: Create a plugin by flutter create 2: Add C/C++ sources 3: Load the code using the FFI library 4: Run on iPhone
works well: flutter create --platforms=android,ios --template=plugin native_add
crash happen: flutter create -a java -i objc --platforms=android,ios --template=plugin native_add