Rethinking Dart interoperability with Android
HTML-код
- Опубликовано: 9 май 2023
- In the past, Flutter only supported integration with Android libraries through a message-based approach called platform channels. With a new command using JNI to bridge to Android system APIs, Flutter developers can easily access platform APIs without needing to use a platform channel or plugin. This session will dive deeper into how Dart automatically creates bindings for cross-language interoperation and demo how to call a Jetpack Library directly from Dart in a Flutter app.
Resources:
Java interop → goo.gle/3GilmDA
Full sample code → goo.gle/3KfwORI
Demo code → goo.gle/3KAvp9O
File issues and share feedback → goo.gle/3KU4V3a
Speakers: Mariam Hasnany, Hossein Yousefi
Watch more:
Watch all Flutter Sessions → goo.gle/IO23_flutter
Watch all the Technical Sessions from Google I/O 2023 → goo.gle/IO23_sessions
Watch more Mobile Sessions → goo.gle/IO23_mobile
All Google I/O 2023 Sessions → goo.gle/IO23_all
Subscribe to Flutter! → goo.gle/FlutterYT
#GoogleIO Наука
Watch all Flutter Sessions → goo.gle/IO23_flutteryt_pin
I'm really glad to see this progress in this area. 🎉
Wow 🎉🎉🎉🎉
Flutter is going far and deep 👏👏👏
Hossein Yousefi is so well spoken!
Wow this is so cool.
Great great team of Flutter and Dart. I ❤ this community
amazing 🎉
Excellent! There're much capabilities already in the Java space. The more we can use them through Dart, better/faster the applications would be able to ship to the customer!
Great 😃
very good
Tem diferença entre canal e a chamada plataforma ?
cool!
awesome feature
do you have any reference video for the pigeon to work with C++ library? couldn't find enough to understand better?
Why didn't they use jnigen for the flutter camera plugin?
JNIgen is still experimental and pigeon made sense for our rewrite for the camera plugin (we wanted to release with 3.10) to use CameraX api because it kept our implementation and architecture the same for the plugin used across multiple platforms. If Camera plugin was only for Android usage, JNIgen would have made more sense. As JNIgen becomes more stable we will do a better job of explaining when to use JNIgen vs pigeon vs method channels.
its pretty confusing for native developer to write native code in dart
what is the difference between platform channel and jnigen?
with platform (method) channels you have to write both Dart code for the Android API and a bunch of platform-specific code for handlers to send a receive messages from dart to native. JNIgen automatically generates Dart bindings for Android APIs available in Java or Kotlin code. After generating the bindings, you can go ahead and call the API like any other Dart code without needing to write any handlers because the bindings do that for you.
Not sure the difference between a Flutter Plugin vs Package, but I'd like to make a Flutter Windows/Desktop application that can access peripherals via their DLL drivers/library.
From what I've seen FFI/JNIGen , Pigeon, or platform-channels must be used, but not sure how. For example, the DLL exports functions that return pointers to structures (that in turn have enums and other structures as its member elements). Would love to see such a hello-world style Flutter (3.11?) application!
Finally.
will the final apk contain all the methods or only the ones that were used?
It will contain no classes/method by default in the release mode since they're all going to be tree-shaken. You will have to manually add the classes and methods you want to keep using proguard rules. We have an open issue to automatically generate the proguard rules in the future.
👏👏👏👏👏
It would be great if you can call Compose directly and cross-platform. I didn’t find such an example code.
Неужели случилась друидская магия и Android либы теперь можно использовать на iOS, десктопе и вебе?
Но подождите, ведь на видео они запускают только Android эмулятор.
Если это другой вариант, как можно написать код только для одной платформы, то я даже не знаю, смеяться над этим или плакать - это "грабли" для потери времени в самом чистейшем виде.
Show an ios example with swift as well
Great, but how to include the other platforms like Windows, Mac, Linux, Web this way?