$30 off During Our Annual Pro Sale. View Details »

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
Tweet

More Decks by Karan Trehan

Other Decks in Technology

Transcript

  1. Writing a modular
    Android Application
    - Karan Trehan
    Android @ m.Paani
    @karntrehan

    View Slide

  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

    View Slide


  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

    View Slide

  4. 4
    Default structure
    Drawbacks:
    ▪ No shared utils
    ▪ Cumbersome code navigation
    ▪ No Instant Apps
    ▪ Slow gradle builds

    View Slide

  5. 5
    Modular structure
    Advantages:
    ▪ Faster gradle builds
    ▪ Re-usability of common functionality
    ▪ Easily “Instant” your apps
    ▪ Better teamwork (Ownership)
    ▪ Smoother Git Flows

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  9. 9
    Language
    Which one do I write my modules in?
    VS

    View Slide

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

    View Slide

  11. 11
    Modules
    What goes in which module?
    ▪ Identify app flows
    ▪ Create feature modules
    ▪ Non-UI modules
    ▪ Examples:
    ▫ authentication
    ▫ onboarding
    ▫ settings
    ▫ account
    ▫ notification

    View Slide

  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

    View Slide

  13. 13
    core
    stores
    rewards home notification
    authentication
    dependent’s build.gradle
    Module dependency structure

    View Slide

  14. 14
    3rd Party Libraries
    Where do I add them and initialize them?
    core’s build.gradle core’s CoreApp.kt

    View Slide

  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

    View Slide

  16. 16
    Dagger 2
    How do I handle my dependencies?

    View Slide

  17. Actual Code
    Implementation!
    ▪ Modular
    ▪ Kotlin
    ▪ Rx
    ▪ Retrofit
    ▪ LiveData
    ▪ ViewModel
    ▪ Tests
    https://github.com/karntrehan/posts
    Place your screenshot here
    17 @karntrehan

    View Slide

  18. THANK YOU!
    Have fun modularizing
    your apps!
    @karntrehan Template from: Mowbray, Link: https://goo.gl/XVJRqH

    View Slide