A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.

Overview

Android Architecture Blueprints v2

Illustration by Virginia Poltrack

Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android apps. In its different branches you'll find the same app (a TODO app) implemented with small differences.

In this branch you'll find:

  • Kotlin Coroutines for background operations.
  • A single-activity architecture, using the Navigation component to manage fragment operations.
  • A presentation layer that contains a fragment (View) and a ViewModel per screen (or feature).
  • Reactive UIs using LiveData observables and Data Binding.
  • A data layer with a repository and two data sources (local using Room and remote) that are queried with one-shot operations (no listeners or data streams).
  • Two product flavors, mock and prod, to ease development and testing (except in the Dagger branch).
  • A collection of unit, integration and e2e tests, including "shared" tests that can be run on emulator/device or Robolectric.

Variations

This project hosts each sample app in separate repository branches. For more information, see the README.md file in each branch.

Stable samples - Kotlin

Sample Description
master The base for the rest of the branches.
Uses Kotlin, Architecture Components, coroutines, Data Binding, etc. and uses Room as source of truth, with a reactive UI.
dagger-android
[compare]
A simple Dagger setup that uses dagger-android and removes the two flavors.
usecases
[compare]
Adds a new domain layer that uses UseCases for business logic.

Old samples - Kotlin and Java

Blueprints v1 had a collection of samples that are not maintained anymore, but can still be useful. See all project branches.

Why a to-do app?

A demo illustraating the UI of the app

The app in this project aims to be simple enough that you can understand it quickly, but complex enough to showcase difficult design decisions and testing scenarios. For more information, see the app's specification.

What is it not?

  • A UI/Material Design sample. The interface of the app is deliberately kept simple to focus on architecture. Check out Plaid instead.
  • A complete Jetpack sample covering all libraries. Check out Android Sunflower or the advanced Github Browser Sample instead.
  • A real production app with network access, user authentication, etc. Check out the Google I/O app, Santa Tracker or Tivi for that.

Who is it for?

  • Intermediate developers and beginners looking for a way to structure their app in a testable and maintainable way.
  • Advanced developers looking for quick reference.

Opening a sample in Android Studio

To open one of the samples in Android Studio, begin by checking out one of the sample branches, and then open the root directory in Android Studio. The following series of steps illustrate how to open the usecases sample.

Clone the repository:

git clone [email protected]:googlesamples/android-architecture.git

This step checks out the master branch. If you want to change to a different sample:

git checkout usecases

Note: To review a different sample, replace usecases with the name of sample you want to check out.

Finally open the android-architecture/ directory in Android Studio.

License

Copyright 2019 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
Comments
  • New Sample: Model View Intent

    New Sample: Model View Intent

    New sample proposal

    I'd like to create a new sample to illustrate the Model View Intent pattern. Full Android examples for MVI are hard to find. It's a pattern that has seen wide adoption in the Javascript and .NET world. Target audience include, but not limited to:

    • Developers making the pivot from an imperative to declarative style of programming.
    • Developers looking for best-practices in functional or reactive programming on Android.

    Here are some articles/examples explaining the core principles of MVI and unidirectional flow:

    • http://hannesdorfmann.com/android/model-view-intent
    • https://cycle.js.org/model-view-intent.html
    • http://thenewstack.io/developers-need-know-mvi-model-view-intent/

    Proposed stack

    I'm hoping to use specific libraries to achieve this in the cleanest possible way. A requirement with the android-architecture samples is to use accepted industry standard. A few of these libraries are new as of this year, but I believe they still fulfill that requirement. I've taken the time to establish a small 'pedigree' for each.

    The following are battle-tested libraries. Battle tested here means that they have documented use, in production, at major companies with a large user base. Places such as Square, Groupon, Trello, Shopify, etc. One notable exception is RxJava2. RxJava 2 has major community backing, and will see a production release later this month.

    Also, the following all have well-know, senior maintainers with established track records. Below a detailed list with rationale/credentials:

    New sample 
    opened by kanawish 20
  • Migration to Dagger Android/Contributes Injector

    Migration to Dagger Android/Contributes Injector

    This pr updates the Dagger sample to now us modern best practices such as subclassing DaggerApplication as well as the new @ContributesInjector construct.

    opened by digitalbuddha 18
  • New Sample: Using Kotlin coroutines

    New Sample: Using Kotlin coroutines

    I'd like to create a sample that demonstrates the power and elegance of Kotlin coroutines. It will use MVVM, Data Binding and Architecture Components (ViewModel and possibly LiveData). I plan to branch it off dev-todo-mvvm-live-kotlin. The suggested new branch name is dev-todo-mvvm-live-kotlin-coroutines.

    The primary objective is to select and consistently apply a small subset of essential Kotlin coroutine idioms.

    New sample community request 
    opened by alex-chiviliov 12
  • Added strict Null-Ptr checks of context or activity in some fragments

    Added strict Null-Ptr checks of context or activity in some fragments

    Because new version has strict check for null-ptr of context or activity in fragments. It would be nice to have new and early experience with this new gradle feature.

    opened by XinyueZ 11
  • New sample: rxjava2

    New sample: rxjava2

    I was surprised to see the rxjava example still uses rxjava 1. Has there been any work related to an example using rxjava 2 or are there plans on doing this ?

    opened by jonasgeiregat 9
  • [all] adding CircleCI configuration file

    [all] adding CircleCI configuration file

    At the moment there is only TravisCI configuration file. Adding those for CircleCI would be fairly easy to do and Jose said it could be a nice addition to the project. I am willing to do it if welcomed. In the case I need to merge on all projects, do I need to create a PR for each or one would be enough for the merge-master to pass it on the others?

    enhancement 
    opened by oldergod 9
  • Error:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

    Error:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

    Error:Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

    opened by shakil807g 8
  • [todo-mvvm] Architecture Components sample

    [todo-mvvm] Architecture Components sample

    I want to integrate the latest architectural components (ViewModel, LiveData, LifeCycleOwner) into the todo-mvvm. Should there be a new branch with the name [todo-mvvm-{newandroidarch/somethingelse}] or should I start editing in this branch only?

    opened by gaurav414u 8
  • Sample using Conductor and a single Activity architecture

    Sample using Conductor and a single Activity architecture

    Hi everyone,

    I decided to try making a sample that only uses a single Activity architecture using the Conductor library.

    I've put the branch up here and I'd really appreciate any feedback!

    It turned out to not be too difficult, the Activities and Fragments became Controllers and everything else stayed the same. I had to do some interesting code around getting the DrawerLayout working and constantly changing the ActionBar to have new stuff in it.

    The main thing left to do is that it broke a few of the Espresso tests and also made most of them super flakey. The problem is that the test no longer knows that it needs to wait while the next Controller loads (I guess Espresso is usually aware of Activity transitions and I no longer have that crutch). I had a look at using IdlingResource to solve this, but I'm not experienced with Conductor or Espresso, I'll keep working on it. Also, the hermetic UI tests of individual Activities will probably never work hermetically since I don't think I can jump into a specific Controller like you can with Activities, you need to navigate there.

    New sample community request 
    opened by grepx 8
  • fix to take care of the order of method calls

    fix to take care of the order of method calls

    Hi,

    Could you please review this ?

    This patch makes the unit test method calls order sensitive.

    I guess the transition from 'true' to 'false' is important for the test. mTasksView).setLoadingIndicator(true); mTasksView).setLoadingIndicator(false);

    opened by sfuku7 8
  • Proposed extension of RxJava usage across all layers of the MVP

    Proposed extension of RxJava usage across all layers of the MVP

    I've built a small example of how we could use RxJava across the View/Presenter bridge. Benefits include the possibility of writing Presenter tests as observable chains, cleaner observable chain building in the presenter (allows for debouncing, more sophisticated UX behavior, etc.)

    Small note on the change to the Contract, I've moved the emitting Observable to the view side. I believe this still respects the MVP model, based on this model:

    image

    Notes:

    • Changes to contract to reflect View's emitter/consumer nature when using Observables.
    • Example of using RxRelay to hide implementation details / lifecycle issues from presenter.
    • Example of using RxBindings on View side.
    • Added RetroLambda support.
    opened by kanawish 8
  • [Question] Which layer for VPN client business logic

    [Question] Which layer for VPN client business logic

    Hello, suppose we are building a vpn client, in which layer should the business logic and service class be placed? In the ui layer corresponding to its feature, or the domain layer

    opened by ErfanSn 0
  • java.lang.IllegalStateException: Method addObserver must be called on the main thread

    java.lang.IllegalStateException: Method addObserver must be called on the main thread

    Hello, I am trying to perform integration testing and use launchFragmentInHiltContainer to start my fragment for specific scenario. However I receive and error java.lang.IllegalStateException: Method addObserver must be called on the main thread on the navController.setGraph(R.navigation.nav_graph) line. Below I have provided my test class and the launchFragmentInHiltContainer.

    @HiltAndroidTest
    class SensorsTests {
    
        @get:Rule
        var hiltRule = HiltAndroidRule(this)
    
        @Inject
        lateinit var repository: MockRepositoryImpl
    
        @BeforeAll
        fun beforeAll() {
            hiltRule.inject()
        }
    
        @Test
        fun userSensorsAreVisible() {
            val navController = TestNavHostController(ApplicationProvider.getApplicationContext())
            navController.setGraph(R.navigation.nav_graph)
    
            launchFragmentInHiltContainer<SensorsFragment>(navHostController = navController)
    
            Thread.sleep(10000)
        }
    
    }
    
    inline fun <reified T : Fragment> launchFragmentInHiltContainer(
        fragmentArgs: Bundle? = null,
        @StyleRes themeResId: Int = R.style.Theme_SensorsTracker,
        navHostController: NavHostController? = null,
        crossinline action: Fragment.() -> Unit = {}
    ) {
        val startActivityIntent = Intent.makeMainActivity(
            ComponentName(
                ApplicationProvider.getApplicationContext(),
                HiltTestActivity::class.java
            )
        ).putExtra(
            "androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity.THEME_EXTRAS_BUNDLE_KEY",
            themeResId
        )
    
        ActivityScenario.launch<HiltTestActivity>(startActivityIntent).onActivity { activity ->
            val fragment: Fragment = activity.supportFragmentManager.fragmentFactory.instantiate(
                Preconditions.checkNotNull(T::class.java.classLoader),
                T::class.java.name
            )
    
            fragment.arguments = fragmentArgs
    
            fragment.viewLifecycleOwnerLiveData.observeForever { viewLifecycleOwner ->
                if (viewLifecycleOwner != null) {
                    navHostController?.let {
                        Navigation.setViewNavController(fragment.requireView(), it)
                    }
                }
            }
    
            activity.supportFragmentManager
                .beginTransaction()
                .add(android.R.id.content, fragment, "")
                .commitNow()
    
            fragment.action()
        }
    }
    
    opened by cjacky475 1
  • Flood logs of

    Flood logs of "AmSubtitle" when using ViewVideo

    Dear Support Team,

    I am using VideoView to run a serie of videos and whenever I check the Logcat I got flood of log with "AmSubtitle".

    I want to remove this Log, what should I do ?

    thank you

    1. Logcat flood log

    2. My code code

    opened by NabilPopo 0
Owner
Android
Android
Multiple samples demonstrating Search API usage in Android.

Search Samples Repository This repository contains a set of individual Android Studio projects to help you get started writing apps that take advantag

Android 41 Nov 23, 2022
This project was created as a demo project for implementing latest frameworks, Android APIs, tools, and techniques.

IWeather Android Application This project was created as a demo project for implementing latest frameworks, Android APIs, tools, and techniques. It fo

Ali Mansour 10 Oct 15, 2022
📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Sunit Roy 28 Oct 27, 2022
Event Trackr Android app. Allows users to track birthdays and anniversaries of friends and family.

Trackr Event Trackr Android app. Allows users to track birthdays and anniversaries of friends and family. You need to open this project in Android Stu

null 4 Feb 3, 2022
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

Madalin Valceleanu 2.3k Nov 25, 2022
Saga of Star wars - An Android sample repo showcasing Clean Arch with MVVM and Epoxy models

Star Wars Universe This is a showcase android application written in Kotlin and follows Clean Code architecture to showcase Characters from the StarWa

Adit Lal 4 Aug 30, 2022
eCommerce app developed with Android Jetpack and Kotlin

garden-shed eCommerce app developed with Android Jetpack and Kotlin This is my first mobile application. Garden Shed is a simple application for buyin

null 2 Nov 1, 2022
An Android project template with MVVM, Hilt, Navigation and Compose

compose-android-template An Android project template with MVVM, Hilt, Navigation and Compose ?? Status UNDER ACTIVE DEVELOPMENT ?? Terminologies Termi

Sifar 20 Oct 20, 2022
A simple android sound recorder which let's users record audio and listen to it

Android-Sound-Recorder A simple android sound recorder which let's users record audio and listen to it. Getting started To get started just clone or f

Nisa Jamalia Nurhayati 0 Nov 4, 2021
This is An Android Project. in which we use SqLite Database. We perform Insert,delete,update and Show The existing data. operations using SqLite.

SqLite Database Keywords : SqLite, Android, Database This is An Android Project. in which we use SqLite Database. We perform Insert,delete,update and

Rudra_deep 1 Nov 7, 2021
Starter code for Android Kotlin Fundamentals Codelab 4.1 Lifecycles and logging.

DessertClicker - Starter Code Starter code for Android Kotlin Fundamentals Codelab 4.1 Lifecycles and logging. Introduction DessertClicker is a game a

null 0 Dec 2, 2021
Android Viper template with Kotlin, Dagger 2, Retrofit & RxJava

Android VIPER Architecture Example This repository contains a detailed sample client-server app that implements VIPER(View-Interactor-Presenter-Entity

OmiSoft 33 Nov 4, 2022
Learn How to use Google Map API for Android from Basic to Advance with complete examples.

Complete-Google-Map-API-Tutorial Learn How to use Google Map API for Android from Basic to Advance. Satellite View 3D Building Map and StreetView Lear

Next 115 Nov 13, 2022
This is an example implementation of android accessibility services with 5 Sample Actions

Android Accessibility Services Example This is an example implementation of android accessibility services with 5 Sample Actions such as: Simulate Pow

Muhammad Fahriansyah 7 Jul 1, 2022
Android Modern Architecture Sample

AndroidModernArchitectureSample TODO: write readme Download (playstore release - under review) https://play.google.com/store/apps/details?id=io.github

Ji Sungbin 22 Sep 10, 2022
Example Android library project that works with jitpack.io

android-example Example Android library project that works with jitpack.io. See this Tutorial on how to publish an Android Library with JitPack. For m

Denys Denysenko 0 Dec 20, 2021
This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity.

Behind the Scenes - DevByte Viewer App This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity. DevByte DevByte Vi

Jaime 1 Oct 20, 2021
LoadApp This is my submission for the "Building an Advanced Android App"

LoadApp This is my submission for the "Building an Advanced Android App" project of the Udacity Android Kotlin Developer nanodegree. (C) Jaldhar H. Vy

Jaldhar H. Vyas 1 Oct 7, 2021
A Project suggested by the Android Basics Course

Dogglers - Starter Code Starter code for the second independent project for Android Basics in Kotlin. Introduction This is the starter code for the Do

Sorin Noroc 2 Aug 31, 2022