Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
FlutterとAndroidの 連携を変えるかもしれないjni
Search
Mikami Hiroki
May 22, 2023
Programming
640
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
FlutterとAndroidの 連携を変えるかもしれないjni
Mikami Hiroki
May 22, 2023
More Decks by Mikami Hiroki
See All by Mikami Hiroki
KMPの今と未来
monaapk
0
620
Accompanistから考えるAndroidの権限許諾
monaapk
0
470
AndroidにおけるWebの進化
monaapk
1
320
DroidKaigi 2022のカンファレンスアプリを眺める
monaapk
2
1.2k
Circuit⚡
monaapk
0
430
Jetpack Compose と Accompanist
monaapk
0
360
Other Decks in Programming
See All in Programming
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
180
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
470
Event is what happens
moro
2
440
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
740
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
150
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.5k
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
150
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
1
350
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
370
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
RailsConf 2023
tenderlove
30
1.6k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
560
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
810
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Transcript
<< FlutterとAndroidの 連携を変えるかもしれないjni DroidKaigi.collect{ #3@Tokyo }
• 株式会社ゆめみ • AndroidとFlutterをぼちぼち • Twitter: @mono33__ みかみ
[1] Rethinking Dart interoperability with Android, https://youtu.be/ZWp2FJ2TuJs
アジェンダ 1. 従来のネイティブ連携 2. jni パッケージについて 3. まとめ
アジェンダ 1. 従来のネイティブ連携 2. jni パッケージについて 3. まとめ
Flutter標準のネイティブ連携 • プラットフォーム固有の機能やAPIは直接扱えない • MethodChannelなど、メッセージによってFlutterと ネイティブ間の連携を可能にする仕組み[2] [2] Writing custom platform-specific
code, https://docs.flutter.dev/platform-integration/platform-channels Flutter Android MethodChannel
MethodChannelの問題点 • クラスの指定や引数、メソッド名を文字列で扱う必要があ る 🤔
Pigeonパッケージの登場 • Flutterとネイティブ間で型安全な連携を可能にする コード生成ツール[3] • Dartでスキーマを記述し、Flutterとプラットフォームの共通 のインターフェースとなるコードを自動生成 [3] Pigeon, https://pub.dev/packages/pigeon
Pigeonのイメージ Flutter Android インターフェース .dart Pigeon インターフェース 1. スキーマの定義 2.
自動生成 3. それぞれ実装
アジェンダ 1. 従来のネイティブ連携 2. jni パッケージについて 3. まとめ
jniパッケージの概要 • Dart / Flutter から Java Native Interface(JNI) への
アクセスをサポートするパッケージ[4] • Android側でDartと連携する処理が不要 🎉 ◦ DartだけでAndroid側の処理を呼び出せる ◦ ContextやActivityを取得するメソッドも用意 [4] jin, https://pub.dev/packages/jni
jniのイメージ [5] jnigen/README.md, https://github.com/dart-lang/jnigen/blob/main/README.md C bindings dart bindings Flutter Java
code JNI jnigen.yaml (設定ファイル) 1. 設定 & 自動生成 2. dart bindings を扱う
4ステップで導入できる
1. 依存関係の追加 • pubspec.yamlにjniとjnigen[6]を追加 [6] jnigen, https://pub.dev/packages/jnigen
2. 設定ファイル(jnigen.yaml)の記述 • 自動生成周りの情報を記述 ◦ 自作のコードやAndroidXのライブラリやJavaの標準ラ イブラリも呼び出せる ◦ もちろんKotlinのコードも
jnigen.yamlのイメージ
jnigen.yamlのイメージ 生成するコードの設 定
jnigen.yamlのイメージ 呼び出したい ものの設定
jnigen.yamlのイメージ example.dartに Exampleクラスを呼び出す dart bindingsが生成
3. コードの自動生成 • jnigen.yamlを元にコードを自動生成
4. build.gradleの変更 • jnigenによって生成されるCMakeLists.txtのパスを設定
呼び出し DartだけでAndroid側の 処理を呼び出せる
アジェンダ 1. 従来のネイティブ連携 2. jni パッケージについて 3. まとめ
まとめ • jniはPigeonとは別アプローチでネイティブ連携を行う • 癖はあるがDartだけでネイティブの実装を呼び出せる • まだまだ🚧開発中🚧
補足・参考 • Swift 向けにffi[7]/ffigen[8]が開発されている • 公式にpedometer[9]というjni・ffiを使った サンプルのリポジトリ [7] ffi, https://pub.dev/packages/ffi
[8] ffigen, https://pub.dev/packages/ffigen [9] pedometer, https://github.com/flutter/samples/tree/main/experimental/pedometer
References • [1] Rethinking Dart interoperability with Android, https://youtu.be/ZWp2FJ2TuJs •
[2] Writing custom platform-specific code, https://docs.flutter.dev/platform-integration/platform-channels • [3] Pigeon, https://pub.dev/packages/pigeon • [4] jin, https://pub.dev/packages/jni • [5] jnigen/README.md, https://github.com/dart-lang/jnigen/blob/main/README.md • [6] jnigen, https://pub.dev/packages/jnigen • [7] ffi, https://pub.dev/packages/ffi • [8] ffigen, https://pub.dev/packages/ffigen • [9] pedometer, https://github.com/flutter/samples/tree/main/experimental/pedometer
CREDITS: This presentation template was created by Slidesgo, including icons
by Flaticon, infographics & images by Freepik. Thanks!