Slide 1

Slide 1 text

Himanshu Singh @hi_man_shoe Modularizing your Android App

Slide 2

Slide 2 text

Himanshu Singh @hi_man_shoe About Me? Sr Android Engineer @roomiapp Instructor and open source contributor @ Mindorks.com

Slide 3

Slide 3 text

Android Developers ?

Slide 4

Slide 4 text

Android Developers ?

Slide 5

Slide 5 text

Let’s Talk about the problem

Slide 6

Slide 6 text

Let’s Talk about the problem ચાલો શરૂ કરીએ ?

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Module Bug Release Android Development Graph Feature

Slide 9

Slide 9 text

Solution to this ??

Slide 10

Slide 10 text

Multi - Modules

Slide 11

Slide 11 text

What and Whys of Multi Modules

Slide 12

Slide 12 text

Let’s talk about What

Slide 13

Slide 13 text

Let’s Talk about What Why

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Library Modules Dynamic Delivery Modules

Slide 16

Slide 16 text

Library Modules Dynamic Delivery Modules

Slide 17

Slide 17 text

Let’s start with the code

Slide 18

Slide 18 text

Let’s start with the code

Slide 19

Slide 19 text

Create an Android Project (App Module)

Slide 20

Slide 20 text

Create an Android Project (App Module)

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Create an Android Project (App Module) Goto File-> New -> New Module and select Dynamic Feature Module (>Kitkat)

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

On the next screen, you will get a few options to configure your module.

Slide 25

Slide 25 text

On the next screen, you will get a few options to configure your module.

Slide 26

Slide 26 text

Press Finish :)

Slide 27

Slide 27 text

Final Project Looks like :)

Slide 28

Slide 28 text

What we want to achieve ?

Slide 29

Slide 29 text

Slide 30

Slide 30 text

android { ....... dynamicFeatures = [":news_feature"] } In app’s build.gradle file

Slide 31

Slide 31 text

apply plugin: 'com.android.dynamic-feature' dependencies { ..... implementation project(':app') } In new_feature’s build.gradle file

Slide 32

Slide 32 text

In the manifest of the dynamic Module,

Slide 33

Slide 33 text

Slide 34

Slide 34 text

Slide 35

Slide 35 text

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,

Slide 36

Slide 36 text

Pro Tip #1 ● Treat the dynamic-module as the individual app itself

Slide 37

Slide 37 text

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,

Slide 38

Slide 38 text

This is our project

Slide 39

Slide 39 text

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,

Slide 40

Slide 40 text

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,

Slide 41

Slide 41 text

Let's learn how to make the dynamic-feature downloadable from the app's module.

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

override fun onCreate(savedInstanceState: Bundle) { .... initDynamicModules() } private fun initDynamicModules() { splitInstallManager = SplitInstallManagerFactory.create(this) request = SplitInstallRequest .newBuilder() .addModule(DYNAMIC_FEATURE) .build(); } In App’s MainActivity

Slide 44

Slide 44 text

Implement Clicks :)

Slide 45

Slide 45 text

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 } } }

Slide 46

Slide 46 text

In App’s MainActivity private fun isDynamicFeatureDownloaded(feature: String): Boolean = splitInstallManager.installedModules.contains(feature)

Slide 47

Slide 47 text

In App’s MainActivity private fun downloadFeature() { splitInstallManager.startInstall(request) .addOnFailureListener { //on Failure Handle } .addOnSuccessListener { buttonOpenNewsModule.visibility = View.VISIBLE buttonDeleteNewsModule.visibility = View.VISIBLE } .addOnCompleteListener { } }

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Let’s Open the News Activity

Slide 50

Slide 50 text

In App’s MainActivity buttonOpenNewsModule.setOnClickListener { val intent = Intent() .setClassName(this, "com.mindorks.news_feature.newsloader.NewsLoaderActivity") startActivity(intent) }

Slide 51

Slide 51 text

In App’s MainActivity buttonOpenNewsModule.setOnClickListener { val intent = Intent() .setClassName(this, "com.mindorks.news_feature.newsloader.NewsLoaderActivity") startActivity(intent) }

Slide 52

Slide 52 text

In App’s MainActivity buttonDeleteNewsModule.setOnClickListener { val list = listOf(DYNAMIC_FEATURE) splitInstallManager.deferredUninstall(list) .addOnSuccessListener { buttonDeleteNewsModule.visibility = View.GONE buttonOpenNewsModule.visibility = View.GONE } }

Slide 53

Slide 53 text

Library Modules

Slide 54

Slide 54 text

Create an Android Project (App Module) Goto File -> New -> New Module

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

And Use it how you use other libraries :)

Slide 57

Slide 57 text

Pro Tip #2 ● Checkout Darshan’s Talk to understand this module for the library creation

Slide 58

Slide 58 text

When ???

Slide 59

Slide 59 text

Library Modules Dynamic Delivery Modules

Slide 60

Slide 60 text

Library Modules Dynamic Delivery Modules

Slide 61

Slide 61 text

Why this approach ???

Slide 62

Slide 62 text

● Easily Manageable By Multiple Devs ● Maintainability ● Reduced APK Size ● Testing New Features

Slide 63

Slide 63 text

● Easily Manageable By Multiple Devs ● Maintainability ● Reduced APK Size ● Testing New Features

Slide 64

Slide 64 text

● Easily Manageable By Multiple Devs ● Maintainability ● Reduced APK Size ● Testing New Features

Slide 65

Slide 65 text

● Easily Manageable By Multiple Devs ● Maintainability ● Reduced APK Size ● Testing New Features

Slide 66

Slide 66 text

Link to project https://tiny.cc/gdgahm

Slide 67

Slide 67 text

Any Question? Himanshu Singh @hi_man_shoe

Slide 68

Slide 68 text

Thanks :) Himanshu Singh @hi_man_shoe