Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
FlutterとAndroidの 連携を変えるかもしれないjni
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Mikami Hiroki
May 22, 2023
Programming
620
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
590
Accompanistから考えるAndroidの権限許諾
monaapk
0
460
AndroidにおけるWebの進化
monaapk
1
310
DroidKaigi 2022のカンファレンスアプリを眺める
monaapk
2
1.1k
Circuit⚡
monaapk
0
410
Jetpack Compose と Accompanist
monaapk
0
340
Other Decks in Programming
See All in Programming
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
Vite+ Unified Toolchain for the Web
naokihaba
0
290
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
260
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
110
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
270
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
510
Lessons from Spec-Driven Development
simas
PRO
0
180
Contextとはなにか
chiroruxx
1
300
RTSPクライアントを自作してみた話
simotin13
0
580
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
10
3k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
580
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Mind Mapping
helmedeiros
PRO
1
250
Chasing Engaging Ingredients in Design
codingconduct
0
220
Raft: Consensus for Rubyists
vanstee
141
7.5k
Site-Speed That Sticks
csswizardry
13
1.2k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
580
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!