Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Writing a modular Android Application

Karan Trehan
February 24, 2018

Writing a modular Android Application

Talk given at the Mumbai Android Developers Meetup on the 24th of February 2018.

Covers the need and process for modularizing an Android app.

Article here: https://medium.com/mindorks/writing-a-modular-project-on-android-304f3b09cb37

Project here: https://github.com/karntrehan/Posts/

Karan Trehan

February 24, 2018

More Decks by Karan Trehan

Other Decks in Technology


  1. What? What is a modular Android Application? How? How do

    I go about making my app modular? Why? Why do I or my users need it? 2
  2. “ 3 What? Modular programming is a software design technique

    that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality. -https://en.wikipedia.org/wiki/Modular_programming
  3. 4 Default structure Drawbacks: ▪ No shared utils ▪ Cumbersome

    code navigation ▪ No Instant Apps ▪ Slow gradle builds
  4. 5 Modular structure Advantages: ▪ Faster gradle builds ▪ Re-usability

    of common functionality ▪ Easily “Instant” your apps ▪ Better teamwork (Ownership) ▪ Smoother Git Flows
  5. Initial doubts with a modular Android App ▪ What architecture

    do I use? ▪ Is my choice of language going to impact me? ▪ How do I define my modules? ▪ What is a core module? ▪ How do I use 3rd party libraries? ▫ Room? ▫ Dagger 2? 6
  6. Architecture Which one do I choose? MVP Presenter communicates between

    the view and the model 7 MVVM Viewmodel communicates between the view and the model Clean Like MVP, the model contains use cases which can be shared across multiple models MVI For each user action an intent is dispatched by the View and observed by the Presenter Reductor Redux inspired to make state mutations easier to read, write and reason about Custom Your custom implementation
  7. CHOOSE ANY! Your architecture choices in no way impact the

    modular-ness of your app! Better, you can have different architectures in different modules. 8
  8. 11 Modules What goes in which module? ▪ Identify app

    flows ▪ Create feature modules ▪ Non-UI modules ▪ Examples: ▫ authentication ▫ onboarding ▫ settings ▫ account ▫ notification
  9. 12 Core Module Why do I need one? ▪ Utility

    classes and extension functions ▪ Global classes and callbacks ▪ Initiate libraries ▪ Provides global dependencies to dependency injection framework
  10. 14 3rd Party Libraries Where do I add them and

    initialize them? core’s build.gradle core’s CoreApp.kt
  11. 15 Room How do I use this awesome library? ▪

    New db into each feature module ▪ Migrations are modularized ▪ Instant apps contain only those tables they need ▪ Queries will be faster
  12. Actual Code Implementation! ▪ Modular ▪ Kotlin ▪ Rx ▪

    Retrofit ▪ LiveData ▪ ViewModel ▪ Tests https://github.com/karntrehan/posts Place your screenshot here 17 @karntrehan