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
Transcript
38 slides
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
ありがとうございました
More Decks by star_zero
See All by star_zero
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1.7k
Jetpack Compose の Side-effect を使いこなす / DroidKaigi 2023
star_zero
5
7.3k
Android 14 新機能 / Android 14 Meetup Nagoya
star_zero
1
710
Android 14 と Predictive back gesture / Shibuya.apk #42
star_zero
0
530
Coroutines Test 入門 / Android Test Night #8
star_zero
2
1.4k
What's new in Jetpack / I/O Extended Japan 2022
star_zero
1
740
Kotlin 2021 Recap / DevFest 2021
star_zero
3
1.4k
Kotlin Symbol Processing (KSP) を使ったコード生成 / DroidKaigi 2021
star_zero
2
5.4k
What's new Android 12
star_zero
0
640
Other Decks in Programming
See All in Programming
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
960
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
270
Crash Auto Pipelines
veronikapj
1
440
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
Spec-driven Development with AI
simas
PRO
0
2.3k
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
220
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
2.7k
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
300
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
小さなアプリを作って公開するまで
onozaty
0
220
[DroidKnights 2026] Workflow AX 적용기 — 자동 정책 정리부터 E2E까지
dayeon
0
120
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
A designer walks into a library…
pauljervisheath
211
25k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Practical Orchestrator
shlominoach
192
12k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Paper Plane (Part 1)
katiecoart
PRO
3
12k