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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Mikami Hiroki
May 22, 2023
Programming
630
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
610
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
350
Other Decks in Programming
See All in Programming
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
1
150
SREの越境 / SRE Collaboration
y0hgi
2
260
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
340
iOSDC2026登壇資料.pdf
riofujimon
0
170
XHTMLが残したもの
yosuke_furukawa
PRO
2
830
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
130
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
350
Building an Out-of-Order CPU
latte72
1
790
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
7.6k
Heart of Swift Concurrency
koher
0
920
Featured
See All Featured
A Soul's Torment
seathinner
8
3.6k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
We Are The Robots
honzajavorek
0
380
Facilitating Awesome Meetings
lara
57
7.1k
30 Presentation Tips
portentint
PRO
1
400
Build your cross-platform service in a week with App Engine
jlugia
234
19k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.9k
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!