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
Domain-Driven Transformation
hschwentner
2
2.3k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
270
Performance Optimization With LLMs
xleitix
0
140
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
170
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
800
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
280
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
7k
WCS-LA-2024
lcolladotor
0
890
RailsConf 2023
tenderlove
30
1.6k
Paper Plane
katiecoart
PRO
5
54k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Tell your own story through comics
letsgokoyo
1
1.1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Mind Mapping
helmedeiros
1
400
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
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!