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.3k
Android 14 新機能 / Android 14 Meetup Nagoya
star_zero
1
700
Android 14 と Predictive back gesture / Shibuya.apk #42
star_zero
0
520
Coroutines Test 入門 / Android Test Night #8
star_zero
2
1.4k
What's new in Jetpack / I/O Extended Japan 2022
star_zero
1
730
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
640
Other Decks in Programming
See All in Programming
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
R8 の設定見直しでアプリサイズ削減
andpad
0
200
パスワード再設定メールのURLについて知っておこう
uyuki234
0
100
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
960
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
160
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
760
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
110
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
610
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
Kubernetes祭り #2 OP/ED
bells17
0
110
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
590
It's Worth the Effort
3n
188
29k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
520
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Code Reviewing Like a Champion
maltzj
529
40k
Become a Pro
speakerdeck
PRO
31
6.3k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
The Pragmatic Product Professional
lauravandoore
37
7.5k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Language of Interfaces
destraynor
162
27k
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
ありがとうございました