📚 Android Components Architecture in a Modular Word

Wonder kotlin pattern application the use of android parts structure in a modular venture

Over years Android structure advanced to make stronger production-quality apps on any scale occupied with serving to builders to design powerful, testable, and maintainable apps. For that Google has promoted in the ultimate years Kotlin as an legit Android programming language impulse by the use of a sequence of community-led occasions like Kotlin/All over and programmers Udacity lessons Kotlin Bootcamp. And it’s not for much less since the benefits are never-ending with recognize to Java providing fashionable statically typed programming language that can spice up your productiveness and build up your developer happiness.

However to begin with, if you wish to take a look at at once the venture sooner than proceeding studying the creation, you’ll be able to do through having access to the next hyperlink:

The programming paradigm in android has observed a drastic flip with the creation of Android Jetpack a suite of libraries, gear, and steering to assist builders write top of the range apps more straightforward. Those parts will let you to apply best possible practices, loose you from writing boilerplate code, and simplify complicated duties. That has ended up giving upward thrust to what’s recognized as of late as Fashionable Android Building.
Android Architecture Components are a part of Jetpack and are a number of libraries that will let you design powerful, testable, and maintainable apps. Get started with categories for managing your UI element lifecycle and dealing with information endurance. 
The under diagram demonstrates how would an application that makes use of this instrument design methodology, even if if you wish to see extra, I like to recommend the next hyperlink.

Modularized app with more than one unbiased facets what proportion or no longer the similar libraries. 

But in the case of combining all structure puzzles in combination into easy consumer application it’s tough to search out open-sourced app pattern to apply. Because of this, I determined to construct one based totally, follow and strictly complies with each and every of the next 5 issues:

The venture items a fashionable, 2019 technique to Android application building the use of Kotlin and newest tech-stack.

The function of the venture is to show best possible practices, supply a set of pointers, modular application, scalable, maintainable and testable. This application might glance easy, however it has all of those small main points that can set the rock-solid basis of the bigger app appropriate for larger groups and lengthy application lifecycle control.

Application construction

One of the vital key advantages of modularization structure is meant to be transparent navigation all through the app and supply code. Having a look on the root folder of the venture, the next construction turns into transparent:

Interplay between modules

Between the modules is established a dependency dating that permits us to make an API request, get admission to to DDBB or use a sure initialized library. Reusing the code in this manner and averting duplicating. The under graph displays the app dependency between modules:

  • :app is determined by :core and not directly is determined by :facets through dynamic-features.
  • :facets modules rely on :commons:core, :app and a few particular utils:library that can use.
  • :core and :commons most effective is determined by conceivable utils on :libraries.
  • :libraries don’t have any dependency.

App module

Core module

The :core module is a com.android.library for serving community requests or having access to to the DDBB. Offering the information supply for the various facets that require it.

Options modules

The :facets module are a com.android.dynamic-feature is basically a gradle module which can also be downloaded independently from the bottom application module. It will probably grasp code and assets and come with dependencies, identical to some other gradle module.

Commons modules

The :commons modules are a com.android.library most effective comprises code and assets which might be shared between characteristic modules. Reusing this manner layouts, perspectives, and different parts in the other facets modules, with out the wish to reproduction code.

Libraries modules

The :libraries modules are a com.android.library, principally comprises other utilities that can be utilized through the other modules.

Architecture parts

Preferably, ViewModels shouldn’t know the rest about Android. This improves testability, leak protection and modularity. ViewModels have other scopes than actions or fragments. Whilst a ViewModel is alive and operating, an process can also be in any of its lifecycle states. Actions and fragments can also be destroyed and created once more whilst the ViewModel is unaware.

Passing a reference of the View (process or fragment) to the ViewModel is a critical chance. Shall we embrace the ViewModel requests information from the community and the information comes again someday later. At that second, the View reference could be destroyed or could be an outdated process this is not visual, producing a reminiscence leak and, most likely, a crash.

The verbal exchange between the other layers follows the above diagram the use of the reactive paradigm, gazing adjustments on parts with out the will of callbacks averting leaks and edge instances associated with them.

Configuration information

With App Modularization we need to acquire fine-grained dependency regulate however we additionally wish to be sure we don’t finally end up keeping up more than one configuration information.

For that we have got the next not unusual configuration information:

The next android-dynamic-feature.gradle.kts is carried out to each characteristic module with the next line:

plugins  identity("commons.android-dynamic-feature")

Issues to believe

After all, not anything is very best, particularly if it has not too long ago pop out. Listed below are some problems what I discovered right through building:

  • Navigation element don’t make stronger more than one back-stack for the instant. Exist other workarounds however no longer formally approach to this. (factor)
  • Robolectric isn’t suitable with dynamic-features modules for the instant. Check on dynamic-feature throws the next exception. The similar take a look at however below android-library , works appropriately. (factor)
  • java.lang.RuntimeException:java.lang.UnsupportedOperationException: libraries no longer supported but
    
  • Roboelectric throw the next exception on checking out apps with data-binding in module. (factor)
  • java.lang.NoClassDefFoundError:androidx/databinding/DataBinderMapperImpl
    
  • MockK with LiveData dependency throws exception when attempt to download price. (factor). The workaround is to make use of mockito for the instant. 
  • java.lang.ClassCastException:java.lang.Object can't be solid to java.lang.String
    

Further Sources

– Initiatives

That is venture is a pattern, to encourage you and must care for many of the not unusual instances, however clearly no longer all. If you wish to have to take a have a look at further assets to search out answers to your venture, consult with those fascinating tasks:

– Articles

A number of very fascinating articles associated with ultimate android network dispositions and suggestions for beginning to take in attention to your present/subsequent venture:

– Libraries

The open-source network create and maintains lots of superior libraries making your task more straightforward, giving the chance to make use of them in your trends. Here’s a crucial number of them:

Keep away from reinventing the wheel through following those pointers:

– Abstract

There are particular advantages in writing or migrating to Modular App and the use of Architecture Components with them. 

  • Quicker construct instances.
  • High quality-grained dependency regulate.
  • Give a boost to reusability throughout different apps.Improves the possession & the standard of the codebase.
  • Stricter limitations when in comparison to programs.
  • Encourages Open Supply of the newly created libraries.
  • Makes Quick Apps & Dynamic Options conceivable (bettering discoverability).
Take note, protecting modules Blank improves testability and eases long run refactoring in case it must be shared between more than one user-facing facets.

The purpose of this text was once to offer a transient evaluate of combining all structure puzzles in combination into your present/subsequent venture. In case you have any questions, enhancements, suggestions about modularisation and structure parts please upload your reaction 🙂.

The total open-source code can also be discovered on GitHub:

Thank you to your time and studying.

V.Madalin