Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Modularizing your Android App
Search
Himanshu Singh
October 12, 2019
Technology
0
270
Modularizing your Android App
This PPT is about Modularising your Android App using dynamic delivery.
Himanshu Singh
October 12, 2019
Tweet
Share
More Decks by Himanshu Singh
See All by Himanshu Singh
FOMO in Android
himanshoe
1
720
Composing your Canvas : DroidCon
himanshoe
2
390
Composing in your Canvas
himanshoe
0
110
Backend Engineering for Android Developers
himanshoe
0
450
Mastering CameraX API
himanshoe
0
120
kotlin.pdf
himanshoe
0
72
Golang.pdf
himanshoe
0
150
DSC PPTX
himanshoe
0
110
Other Decks in Technology
See All in Technology
統計的学習理論読み Chapter 2
kmatsui
1
190
任意コード実行の原理
ffri
0
170
KubeCon EU: Unlocking new Platform Experiences with Open Interfaces
salaboy
1
370
期待しすぎずに取り組む両面 TypeScript
shozawa
2
290
エンジニア候補者向け資料2024.03.28.pdf
macloud
0
2.9k
実務への応用例から考える 変更に強いオブジェクト指向設計 / 20240324-ooc2024
bengo4com
7
5.2k
LLMプロダクト事業の立ち上げにおける挑戦
layerx
PRO
7
1.4k
業務で使えるかもしれない…!?GitHub Actions の Tips 集 / CI/CD Test Night #7
ponkio_o
PRO
24
6.9k
チーム単位で保守性を高める:独自指標と向上にむけた実践
tarappo
0
300
.NETの非同期戦略とUnityとの相互運用
neuecc
2
2.4k
Evolutionary Optimization of Model Merging Recipes
fuyu_quant0
3
520
技術広報として2023年度に頑張ったこと / What we did well in FY2023 as a DevRel
pauli
5
460
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
71
5.1k
Design by the Numbers
sachag
274
18k
Fantastic passwords and where to find them - at NoRuKo
philnash
35
2.4k
BBQ
matthewcrist
78
8.7k
How GitHub Uses GitHub to Build GitHub
holman
467
290k
Robots, Beer and Maslow
schacon
PRO
154
7.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
111
35k
JazzCon 2018 Closing Keynote - Leadership for the Reluctant Leader
reverentgeek
178
11k
Debugging Ruby Performance
tmm1
68
11k
The Invisible Side of Design
smashingmag
293
49k
The Invisible Customer
myddelton
114
12k
Into the Great Unknown - MozCon
thekraken
10
830
Transcript
Himanshu Singh @hi_man_shoe Modularizing your Android App
Himanshu Singh @hi_man_shoe About Me? Sr Android Engineer @roomiapp Instructor
and open source contributor @ Mindorks.com
Android Developers ?
Android Developers ?
Let’s Talk about the problem
Let’s Talk about the problem ચાલો શરૂ કરીએ ?
None
Module Bug Release Android Development Graph Feature
Solution to this ??
Multi - Modules
What and Whys of Multi Modules
Let’s talk about What
Let’s Talk about What Why
None
Library Modules Dynamic Delivery Modules
Library Modules Dynamic Delivery Modules
Let’s start with the code
Let’s start with the code
Create an Android Project (App Module)
Create an Android Project (App Module)
None
Create an Android Project (App Module) Goto File-> New ->
New Module and select Dynamic Feature Module (>Kitkat)
None
On the next screen, you will get a few options
to configure your module.
On the next screen, you will get a few options
to configure your module.
Press Finish :)
Final Project Looks like :)
What we want to achieve ?
<RelativeLayout> <Button android:id="@+id/buttonClick"/> <Button android:id="@+id/buttonOpenNewsModule android:visibility="gone"/> <Button android:id="@+id/buttonDeleteNewsModule" android:visibility="gone"/> </RelativeLayout>
android { ....... dynamicFeatures = [":news_feature"] } In app’s build.gradle
file
apply plugin: 'com.android.dynamic-feature' dependencies { ..... implementation project(':app') } In
new_feature’s build.gradle file
<dist:module dist:instant="false" dist:onDemand="true" dist:title="@string/title_news_feature"> <dist:fusing dist:include="true"/> </dist:module> In the manifest
of the dynamic Module,
<dist:module dist:instant="false" dist:onDemand="true" dist:title="@string/title_news_feature"> <dist:fusing dist:include="true"/> </dist:module>
<dist:module dist:instant="false" dist:onDemand="true" dist:title="@string/title_news_feature"> <dist:fusing dist:include="true"/> </dist:module>
implementation 'com.google.android.play:core:1.6.3' To make your module downloadable on demand add
the following in the app-module's build.gradle,
Pro Tip #1 • Treat the dynamic-module as the individual
app itself
dependencies { ..... api 'androidx.appcompat:appcompat:1.0.2' api 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.play:core:1.6.1' }
In the manifest of the app’s module,
This is our project
dependencies { ..... api 'androidx.appcompat:appcompat:1.0.2' api 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.play:core:1.6.1' }
In the manifest of the app’s module,
dependencies { ..... api 'androidx.appcompat:appcompat:1.0.2' api 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.play:core:1.6.1' }
In the manifest of the app’s module,
Let's learn how to make the dynamic-feature downloadable from the
app's module.
class MainActivity : AppCompatActivity() { lateinit var splitInstallManager: SplitInstallManager lateinit
var request: SplitInstallRequest val DYNAMIC_FEATURE = "news_feature" override fun onCreate(savedInstanceState: Bundle?) { .... } } In App’s MainActivity
override fun onCreate(savedInstanceState: Bundle) { .... initDynamicModules() } private fun
initDynamicModules() { splitInstallManager = SplitInstallManagerFactory.create(this) request = SplitInstallRequest .newBuilder() .addModule(DYNAMIC_FEATURE) .build(); } In App’s MainActivity
Implement Clicks :)
In App’s MainActivity override fun onCreate(savedInstanceState: Bundle) { ........ buttonClick.setOnClickListener
{ if (!isDynamicFeatureDownloaded(DYNAMIC_FEATURE)) { downloadFeature() } else { buttonDeleteNewsModule.visibility = View.VISIBLE buttonOpenNewsModule.visibility = View.VISIBLE } } }
In App’s MainActivity private fun isDynamicFeatureDownloaded(feature: String): Boolean = splitInstallManager.installedModules.contains(feature)
In App’s MainActivity private fun downloadFeature() { splitInstallManager.startInstall(request) .addOnFailureListener {
//on Failure Handle } .addOnSuccessListener { buttonOpenNewsModule.visibility = View.VISIBLE buttonDeleteNewsModule.visibility = View.VISIBLE } .addOnCompleteListener { } }
None
Let’s Open the News Activity
In App’s MainActivity buttonOpenNewsModule.setOnClickListener { val intent = Intent() .setClassName(this,
"com.mindorks.news_feature.newsloader.NewsLoaderActivity") startActivity(intent) }
In App’s MainActivity buttonOpenNewsModule.setOnClickListener { val intent = Intent() .setClassName(this,
"com.mindorks.news_feature.newsloader.NewsLoaderActivity") startActivity(intent) }
In App’s MainActivity buttonDeleteNewsModule.setOnClickListener { val list = listOf(DYNAMIC_FEATURE) splitInstallManager.deferredUninstall(list)
.addOnSuccessListener { buttonDeleteNewsModule.visibility = View.GONE buttonOpenNewsModule.visibility = View.GONE } }
Library Modules
Create an Android Project (App Module) Goto File -> New
-> New Module
None
And Use it how you use other libraries :)
Pro Tip #2 • Checkout Darshan’s Talk to understand this
module for the library creation
When ???
Library Modules Dynamic Delivery Modules
Library Modules Dynamic Delivery Modules
Why this approach ???
• Easily Manageable By Multiple Devs • Maintainability • Reduced
APK Size • Testing New Features
• Easily Manageable By Multiple Devs • Maintainability • Reduced
APK Size • Testing New Features
• Easily Manageable By Multiple Devs • Maintainability • Reduced
APK Size • Testing New Features
• Easily Manageable By Multiple Devs • Maintainability • Reduced
APK Size • Testing New Features
Link to project https://tiny.cc/gdgahm
Any Question? Himanshu Singh @hi_man_shoe
Thanks :) Himanshu Singh @hi_man_shoe