Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Dynamic feature moduleの基本 / Cookpad.apk #2
star_zero
February 18, 2019
Programming
3
6k
Dynamic feature moduleの基本 / Cookpad.apk #2
star_zero
February 18, 2019
Tweet
Share
More Decks by star_zero
See All by star_zero
What's new in Jetpack / I/O Extended Japan 2022
star_zero
1
180
Kotlin 2021 Recap / DevFest 2021
star_zero
3
930
Kotlin Symbol Processing (KSP) を使ったコード生成 / DroidKaigi 2021
star_zero
2
4.5k
What's new Android 12
star_zero
0
370
これからはじめるAndroid開発 / DevFest 2020
star_zero
5
600
Kotlin Coroutines & Android
star_zero
3
660
Dynamic Feature Module in Practice / DroidKaigi 2020
star_zero
2
600
Internal App Sharing🤝gradle-play-publisher と FakeSplitInstallManagerの話 / Cookpad.apk #4
star_zero
0
130
Android cookpadLiveの開発改善 / cookpad_tech_kitchen#23
star_zero
1
580
Other Decks in Programming
See All in Programming
[DevTrends - Jun/2022] Arquitetura baseada em eventos
camilacampos
0
160
Let's keep Commodore 64 alive for the next 40 years
mehowte
1
110
Deep Dive Into Google Zanzibar and its Concepts for Authorization Scenarios
dschenkelman
1
140
Get Ready for Jakarta EE 10
ivargrimstad
0
2.8k
チームでカレーを作ろう!アジャイルカレークッキング
akitotsukahara
0
880
NEWT.net: Frontend Technology Selection
xpromx
0
280
Terraform Plan/Apply結果の自動通知
ymmy02
0
280
The strategies behind ddd – AdeoDevSummit 2022
lilobase
PRO
5
260
Jetpack Composeでの画面遷移
iwata_n
0
190
ES2022の新機能
smt7174
0
270
Power Automateドリブンのチームマネジメント
hanaseleb
0
200
Licences open source : entre guerre de clochers et radicalité
pylapp
2
510
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
119
28k
How GitHub Uses GitHub to Build GitHub
holman
465
280k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
19
1.4k
The Web Native Designer (August 2011)
paulrobertlloyd
74
1.9k
Why You Should Never Use an ORM
jnunemaker
PRO
47
7.6k
Six Lessons from altMBA
skipperchong
14
1.4k
Designing the Hi-DPI Web
ddemaree
272
32k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
151
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
19
1.2k
Stop Working from a Prison Cell
hatefulcrawdad
261
17k
Side Projects
sachag
450
37k
Design by the Numbers
sachag
271
17k
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
ありがとうございました