A boiler plate that can be re-used to start android apps

Overview

Agile Boiler Plate

The main task at the innovation labs of Avast is to find new ideas to work on, prototype these ideas, and quickly implement them. And because this nature of our work we might end up building so many ideas in a very short time. And since quality is something we can’t sacrifice, and since it usually requires additional time we decided to come up with a solid, lean, readable, upgradable, testable boilerplate for our Android apps. We named it Agile Boiler Plate.

This boilerplate covers the needs that most of the Android apps might require. It's simple, well architected and easily adjustable to your specific requirements.

The project is fully based on Dependency Injection design pattern using Dagger2, which adds a layer of separation and makes things even less coupled.

The dependencies currently handled by the boiler plate are the following:

  • Database dependency: encapsulates all the database operations.
  • Shared preferences dependency: deals with shared preferences.
  • Local files dependency: deals with all the operations related to local files.
  • Analytics dependency: covers all the operation of reporting events to your analytics backend (GA, Segment, FB, Flurry ..)
  • Logging dependency: encapsulates all the operations related to logging to your console
  • Api dependency: encapsulates all the API related operations

The power of dependency injection comes really handy especially for testing since you can easily switch your dependencies in the test environment to dummy dependencies.

As an example, you can change your Api dependency in testing environment so it returns a specific response without doing the actual call to your server. Share pref dependency can be overridden to return specific values for certain keys instead of saving and retrieving actual values in your test device, and the same applies for local files and data dependencies. Both logging and analytics dependencies can be overridden to deliver the logs and reports to a server or file to be analyzed after running the tests instead of the console or the actual analytics server.

Moreover, dependency injection makes it really easy when you need to change certain dependencies. Let's say moving from google analytics to flurry, Or migrating from DbFlow database to SQLBrite.

Agile boiler plate consist of 4 layers: View, Presenter, Controller, Model. The communication between the layers is all done using EventBus Design pattern. I'm using a custom bus implemented using RxJava.

Libraries and tools included:

Architecture

The boiler plate is based on MVP architecture (Model, View, Presenter) which is better than MVC when it comes to coupling. MVP makes your view code way cleaner than when using MVC, since the views, activities and the fragments will only have the code related to rendering the customizing the UI and no interactions with the controllers.

MVP architecture

Prerequisites

Running the tests

Tests

To run unit tests on your machine:

./gradlew test

To run instrumentation tests on connected devices:

./gradlew connectedAndroidTest

Code Quality and Style Tools

1- CheckStyle: We are using Checkstyle to insure that the code follows our Android coding style and standards.

The rules we enforce are as the following:

  • Imports rules: which prevents redundant and star imports
  • Naming: sets the rules for naming packages, classes, attributes, parameter, local variables, and types.
  • White Space rules: sets specific rules for white spaces. Things like: nothing can follow a semi-column ';', defining the rules for the white space allowed before the left curly brace '{' and after the right curly brace '}', 1 white space after a comma ',' ....
  • General code styles rules: deals with things like: preventing empty catch, modifiers order (public, static, final, volatile ..)

To run Checkstyle, first you should install the tool on your device or CI server using the following command

brew install checkstyle

and then run the command:

./gradlew checkstyle

2- PMD: Which is a source code analyzer that finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. See this project's PMD ruleset.

Follow this link to check all the rules that PMD enforces.

PMD can be executed using the following command:

./gradlew pmd

3- Findbugs: This tool uses static analysis to look for bugs in Java code. Unlike PMD & Checkstyle, it uses compiled Java bytecode instead of source code.

Follow this link if you want a quick intro about how to configure and start Findbugs. To read more about Findbugs, you can check the following article

Findbugs can be executed using the following command:

./gradlew findbugs

To run the all the previous checks and the unit tests simple run the command

./gradlew check

##Debuging

1- Stetho: Beside using the console and the debugging tools that comes with Android studio, we are using Stetho. The boilerplate is pre-configured to use Stetho in the debug build variant and to avoid it in the release build variant (thanks to dependency injection).

Stetho is a sophisticated debug bridge for Android applications built by facebook which enables developers to have access to the Chrome Developer Tools feature natively part of the Chrome desktop browser.

Here are some of the features it gives:

  • View hierarchy support: for ICS (API 15) and up! Lots of goodies such as instances virtually placed in the hierarchy, view highlighting, and the ability to tap on a view to jump to its position in the hierarchy.
  • Database Inspection: SQLite databases can be visualized and interactively explored with full read/write capabilities.
  • Network Inspection: This is possible with the full spectrum of Chrome Developer Tools features, including image preview, JSON response helpers, and even exporting traces to the HAR format.

To inspect the app using Stetho, simple run the app, make sure the phone is connected to the PC, open the link chrome://inspect in chrome and choose your device.

2- Leak Canary: Which is A memory leak detection library for Android built by Sqaure. Leak canary runs only on debug and it will automatically show a notification when an activity memory leak is detected in your debug build. For more info check this link

Authors

  • Abed Almoradi - Senior Android Developer at Avast - Linkedin

License

This project is licensed under Apache License Version 2.0 - see the LICENSE.md file for details

Acknowledgments

MVP architecture

You might also like...
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

ZXing (
ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Project in Maintenance Mode Only The project is in maintenance mode, meaning, changes are driven by contributed patches. Only bug fixes and minor enha

RxJava binding APIs for Android's UI widgets.

RxBinding RxJava binding APIs for Android UI widgets from the platform and support libraries. Download Platform bindings: implementation 'com.jakewhar

A gradle plugin for getting java lambda support in java 6, 7 and android

Gradle Retrolambda Plugin This plugin will automatically build your java or android project with retrolambda, giving you lambda goodness on java 6 or

A comprehensive tutorial for Android Data Binding
A comprehensive tutorial for Android Data Binding

精通 Android Data Binding 更多干货可移步至个人主页 QQ 交流群:324112728 ,或者点击链接加入QQ群 官方虽然已经给出了教程 - Data Binding Guide (中文版 - Data Binding(数据绑定)用户指南) ,但是实践之后发现槽点实在太多,于是就

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

Development in this repository is stopped. Future development continues on https://github.com/yigit/android-priority-jobqueue ========================

An android library for displaying fps from the choreographer and percentage of time with two or more frames dropped
An android library for displaying fps from the choreographer and percentage of time with two or more frames dropped

DEPRECATED TinyDancer is deprecated. No more development will be taking place. Check out the Google Android developer documentation for UI performance

Memory safer implementation of android.os.Handler
Memory safer implementation of android.os.Handler

Android Weak Handler Memory safer implementation of android.os.Handler Problem Original implementation of Handler always keeps hard reference to handl

Android Library to help you with your runtime Permissions.
Android Library to help you with your runtime Permissions.

PermissionHelper Android Library to help you with your runtime Permissions. Demo Android M Watch it in action. Pre M Watch it in action. Nexus 6 (M) N

Owner
Abed Almoradi
Senior Android developer, currently working for Booking.com
Abed Almoradi
Makes Google play in app purchase library (BillingClient) into a flowable that can easily be used in compose world

Billy the android Our goal is to make a modern api of BillingClient so that it is easier to use in compose world. This library is still early beta and

Stefan Wärting 16 Dec 14, 2022
A .NET Watch Run Configuration (dotnet-watch) that can be used in RiderA .

A .NET Watch Run Configuration (dotnet-watch) that can be used in RiderA .NET Watch Run Configuration (dotnet-watch) that can be used in Rider

Maarten Balliauw 19 Dec 10, 2022
A curated list of standards, tests and benchmarks that can be used for testing and evaluating dev-tools

A curated list of standards, tests and benchmarks that can be used for testing and evaluating dev tools Contribution Add the description of the benchm

null 13 Dec 16, 2022
Over The Air Server for deployment of Android, iOS and macOS apps

Zealot 开源自部署 iOS、Android 及 macOS 应用分发平台,提供 iOS、Android SDK、fastlane 等丰富组件库,打包分发流程、上传应用竟然如此简单、独立部署解决企业使用的烦恼。 En Taro Adun! ?? 特性 支持 iOS、Android 和 macOS

Zealot 687 Dec 28, 2022
BlackBox - a virtual engine, it can clone and run virtual application on Android

BlackBox is a virtual engine, it can clone and run virtual application on Android, users don't have to install APK file to run the application on devices. BlackBox control all virtual applications, so you can do anything you want by using BlackBox.

null 1.6k Jan 3, 2023
Tired of manually setup test data of Kotlin data classes or POJOs? Instantiator creates Instances of any class for you so that you can focus on writing tests instead of spending time and effort to setup test data

Instantiator Tired of manually setup test data of Kotlin data classes or POJOs? Instantiator creates Instances of any class for you so that you can fo

Hannes Dorfmann 54 Dec 30, 2022
A special view that can contain other views (called children)

A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. There

Phạm Thành Trung 1 Oct 16, 2021
A demo of an IOU-like agreement that can be issued, transfered and settled confidentially

The Obligation CorDapp This CorDapp comprises a demo of an IOU-like agreement that can be issued, transfered and settled confidentially. The CorDapp i

null 0 Nov 3, 2021
Starter-Android-Library - Starter Android Library is an Android Project with Modular Architecture.

Starter-Android-Library - Starter Android Library is an Android Project with Modular Architecture.

OpenBytes 1 Feb 18, 2022
SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.

#Scripting Layer for Android (SL4A) SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreter

Damon Kohler 2.3k Dec 23, 2022