Writing a modular Android Application

488785942e3c59ba742ec346dadeffa2?s=47 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/

488785942e3c59ba742ec346dadeffa2?s=128

Karan Trehan

February 24, 2018
Tweet

Transcript

  1. Writing a modular Android Application - Karan Trehan Android @

    m.Paani @karntrehan
  2. 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
  3. “ 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
  4. 4 Default structure Drawbacks: ▪ No shared utils ▪ Cumbersome

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

    of common functionality ▪ Easily “Instant” your apps ▪ Better teamwork (Ownership) ▪ Smoother Git Flows
  6. 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
  7. 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
  8. 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
  9. 9 Language Which one do I write my modules in?

    VS
  10. But, please, give Kotlin a try! Again, CHOOSE ANY! 10

  11. 11 Modules What goes in which module? ▪ Identify app

    flows ▪ Create feature modules ▪ Non-UI modules ▪ Examples: ▫ authentication ▫ onboarding ▫ settings ▫ account ▫ notification
  12. 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
  13. 13 core stores rewards home notification authentication dependent’s build.gradle Module

    dependency structure
  14. 14 3rd Party Libraries Where do I add them and

    initialize them? core’s build.gradle core’s CoreApp.kt
  15. 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
  16. 16 Dagger 2 How do I handle my dependencies?

  17. Actual Code Implementation! ▪ Modular ▪ Kotlin ▪ Rx ▪

    Retrofit ▪ LiveData ▪ ViewModel ▪ Tests https://github.com/karntrehan/posts Place your screenshot here 17 @karntrehan
  18. THANK YOU! Have fun modularizing your apps! @karntrehan Template from:

    Mowbray, Link: https://goo.gl/XVJRqH