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
Dynamic feature moduleの基本 / Cookpad.apk #2
Search
star_zero
February 18, 2019
Programming
6.9k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dynamic feature moduleの基本 / Cookpad.apk #2
star_zero
February 18, 2019
More Decks by star_zero
See All by star_zero
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1.6k
Jetpack Compose の Side-effect を使いこなす / DroidKaigi 2023
star_zero
5
7.2k
Android 14 新機能 / Android 14 Meetup Nagoya
star_zero
1
690
Android 14 と Predictive back gesture / Shibuya.apk #42
star_zero
0
510
Coroutines Test 入門 / Android Test Night #8
star_zero
2
1.4k
What's new in Jetpack / I/O Extended Japan 2022
star_zero
1
720
Kotlin 2021 Recap / DevFest 2021
star_zero
3
1.4k
Kotlin Symbol Processing (KSP) を使ったコード生成 / DroidKaigi 2021
star_zero
2
5.3k
What's new Android 12
star_zero
0
630
Other Decks in Programming
See All in Programming
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1k
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
120
一人だけ、Kiroが静止する日
hideg
0
120
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
440
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
340
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
140
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
1
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
170
すこし踏み込む CancellationToken
htkym
1
500
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
340
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
280
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.2k
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
GraphQLとの向き合い方2022年版
quramy
50
15k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
We Have a Design System, Now What?
morganepeng
55
8.3k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
520
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
How to Talk to Developers About Accessibility
jct
2
550
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Transcript
Dynamic feature module の基本 Cookpad.apk #2
About me •Kenji Abe •メディアプロダクト開発部 •Android cookpadTV •Twitter: @STAR_ZERO
Dynamic feature module (DFM)
概要 •Android App Bundle(aab)の機能 •アプリインストール後に特定のモジュールを 後からインストール ‣ インストール時のファイルサイズ削減 ‣ インストール時に含めることもできる
参考アプリ •Google Santa Tracker
⚠ 注意 ⚠ •まだ、Beta •製品版として公開するときはBeta Programに参加する 必要がある ‣ https://support.google.com/googleplay/android- developer/answer/9006925#beta
• (反映されるまで1-2週間かかる)
DFMをつくる
DFMをつくる •File -> New -> New Module -> Dynamic Feature
Module
DFMをつくる
DFMをつくる •Enable on-demand ‣ 動的配信をするかどうか •Fusing ‣ サポートされてない端末(4.4以下)でインストールさせるか ‣ Enable
on-demandにチェックがあるときのみ
DFMをつくる •Module title ‣ モジュール名 ‣ ダウンロード確認ダイアログで 使用される ‣ (10M超えると確認が必要)
DFMの中身
DFM/AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" package="com.star_zero.sample.dfm.feature1"> <dist:module dist:instant="false" dist:onDemand="true" dist:title="@string/title_feature1"> <dist:fusing
dist:include="true" /> </dist:module> </manifest>
DFM/build.gradle apply plugin: 'com.android.dynamic-feature' android { compileSdkVersion 28 defaultConfig {
minSdkVersion 21 targetSdkVersion 28 } } dependencies { implementation project(':app') implementation project(':core') }
app/build.gradle apply plugin: 'com.android.application' android { // ... dynamicFeatures =
[":feature_one", "feature_two"] } dependencies { implementation project(':core') }
モジュールの依存関係
•よくあるマルチモジュールの依存関係 モジュールの依存関係 feature_one feature_two app implementation project(':feature_one') implementation project(':feature_two')
•DFMの依存関係 モジュールの依存関係 feature_one feature_two app dynamicFeatures = [":feature_one", “feature_two"] implementation
project(':app') implementation project(':app')
Dynamic Delivery
Dynamic Delivery •動的にモジュールをダウンロード •com.google.android.play:core •https://developer.android.com/guide/app-bundle/ playcore
Dynamic Delivery val manager = SplitInstallManagerFactory.create(this) if (manager.installedModules.contains(MODULE_NAME)) { //
インストール済み return } val request = SplitInstallRequest.newBuilder() .addModule(MODULE_NAME) .build() manager.startInstall(request)
Dynamic Delivery val listener = SplitInstallStateUpdatedListener { state -> when
(state.status()) { // ... SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> { // ダウロード確認ダイアログを表示 startIntentSender( state.resolutionIntent()?.intentSender, null, 0, 0, 0) } } } // 登録 manager.registerListener(listener) // 登録解除 manager.unregisterListener(listener)
Dynamic Delivery •モジュールダウンロード後にアクセスするには SplitCompat Libraryが必要 <application … android:name="com.google.android.play.core.splitcompat.SplitCompatApplication"> </application> class
FeatureActivity : AppCompatActivity() { override fun attachBaseContext(newBase: Context?) { super.attachBaseContext(newBase) SplitCompat.install(this) } }
Dynamic Delivery •テストがしにくい ‣ デバッグ実行ではモジュールのダウンロードができない ‣ PlayConsoleの内部テストが必要
実装時のポイント
実装時のポイント •app側からfeatureモジュールは直接参照できない ‣ 参照するにはリフレクションを使う ‣ DIは工夫が必要 (dagger.androidは使わないほうが良いかも)
実装時のポイント •共通処理はcoreモジュールを作っておくと良い ‣ build.gradleでは api でライブラリを追加 ‣ APIアクセスや共通のDI Component ‣
DataBinding (共通の@BindingAdapterなど)
•coreモジュール 実装時のポイント feature_one app core
デバッグ実行
デバッグ実行 •Run -> Edit Configurations…
bundletool
bundletool •aabからapkを作ってくれる •オプションの指定で、モジュールをすべて含んだapkを 作成できる ‣ DeployGate等でapkを配布したい場合など •https://developer.android.com/studio/command- line/bundletool
bundletool $ bundletool build-apks \ --bundle=app.aab \ --output=app.apks \ --ks=release.keystore
\ --ks-pass=pass:sample \ --ks-key-alias=sample \ --key-pass=pass:sample \ --mode=universal # モジュールをすべて含めるオプション $ unzip app.apks # universal.apkが作られる ※universalは <dist:fusing dist:include=“false”/> は含めない
まとめ
まとめ •ダウンロードサイズ削減できる ‣ aab自体でも効果的 ‣ DFMによって更に削減できる •マルチモジュールの手法と捉えられる ‣ ビルド時間短縮 ‣
モジュール分割による設計
まとめ •テストがやりにくい ‣ PlayConsoleの内部テストが必要 •まだまだハマりどころ(バグ?)が多い ‣ DataBinding、Proguard/R8 ‣ 結局やってみないと分からないので色々試す
参考 •https://developer.android.com/studio/projects/dynamic- delivery •https://developer.android.com/guide/app-bundle/playcore •https://github.com/nickbutcher/plaid •https://medium.com/androiddevelopers/google-santa-tracker- moving-to-an-android-app-bundle-dde180716096 •https://www.youtube.com/watch?v=QdoEcfibG-s
ありがとうございました