# Clean Architecture Tutorial for Android: Getting Started | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272>\
**Category:** 🎓 Courses & Articles\
**Created:** [August 5, 2019, 4:10pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272 "2019-08-05T16:10:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikust](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ikust/32/107453_2.png) [@ikust](https://forums.kodeco.com/u/ikust)\
**Post date:** [August 5, 2019, 4:10pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/1 "2019-08-05T16:10:05Z")

</div>

In this tutorial, you’ll learn how to use Clean Architecture on Android to build robust, flexible and maintainable applications.

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/3595916-clean-architecture-tutorial-for-android-getting-started](https://www.raywenderlich.com/3595916-clean-architecture-tutorial-for-android-getting-started)

---

<div class="post-metadata">

**Author:** ![cryptoseven](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cryptoseven/32/81494_2.png) [@cryptoseven](https://forums.kodeco.com/u/cryptoseven)\
**Post date:** [August 16, 2019, 5:59pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/2 "2019-08-16T17:59:36Z")

</div>

Great tutorial!! Thanks 🙂

---

<div class="post-metadata">

**Author:** ![nicolaugalves](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nicolaugalves/32/81494_2.png) [@nicolaugalves](https://forums.kodeco.com/u/nicolaugalves)\
**Post date:** [August 27, 2019, 1:36am UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/3 "2019-08-27T01:36:48Z")

</div>

GlobalScope not work, can you update the tutorial please? Thank you for share your knowledges.

Correction\* I dont know why but GlobalScope bugs import. Download again and sync works!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [September 6, 2019, 12:49am UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/4 "2019-09-06T00:49:03Z")

</div>

@cryptoseven Glad you like it! Cheers! :]

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [September 6, 2019, 12:49am UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/5 "2019-09-06T00:49:37Z")

</div>

@nicolaugalves Glad you sorted it out! Cheers! :]

---

<div class="post-metadata">

**Author:** ![applaudostudios](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/applaudostudios/32/107843_2.png) [@applaudostudios](https://forums.kodeco.com/u/applaudostudios)\
**Post date:** [September 27, 2019, 8:28pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/6 "2019-09-27T20:28:09Z")

</div>

I think the tutorial its really nice  
I just have a concern:  
why are you using _Serializable_ instead of _Parcelabe_ for the models is there any reason in specific?

---

<div class="post-metadata">

**Author:** ![ikust](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ikust/32/107453_2.png) [@ikust](https://forums.kodeco.com/u/ikust)\
**Post date:** [September 30, 2019, 1:34pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/7 "2019-09-30T13:34:08Z")

</div>

Hi,  
thanks, I’m glad you like the tutorial! :]

I’m using Serializable only because it’s easier to implement - wanted to keep the code in sample project as simple as possible.

---

<div class="post-metadata">

**Author:** ![abunur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/abunur/32/109585_2.png) [@abunur](https://forums.kodeco.com/u/abunur)\
**Post date:** [October 14, 2019, 9:45pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/8 "2019-10-14T21:45:49Z")

</div>

Awesome article! One thing I would have liked to have seen though is at least a little bit more of a reference to how the data provider is abstracted. Specifically, maybe a diagram making it clear that you might have both network and local DB acting as data providers, and that it’s the responsibility of the Repository to figure out which to use and how to sync between them.  
 ![41%20PM](https://files.chunter.kodeco.com/original/3X/9/8/987bb3a37d5b3a70035f99b278fae3872e668297.jpeg)

kind of like this. I realize the implementation for this is probably out of scope for a tutorial article like this, though but some reference on how to approach this common pattern or where to go for examples would be great.

---

<div class="post-metadata">

**Author:** ![abunur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/abunur/32/109585_2.png) [@abunur](https://forums.kodeco.com/u/abunur)\
**Post date:** [October 14, 2019, 9:49pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/9 "2019-10-14T21:49:54Z")

</div>

I realize this probably happened during course of writing the article - you started out with a project structure with a certain name but in packaging the tutorial for starter / final projects things may have changed. In the point of the tutorial where you first have the reader do stuff in Android Studio, you say:

Right click on _MajesticReader_ in Project explorer and select _New ▸ Module_ or select _File ▸ New ▸ New Module_

This is incorrect in relation to the project the reader actually downloads, and the screenshots are also incorrect.  
 ![26%20PM](https://files.chunter.kodeco.com/original/3X/3/d/3d9f26601ea7f17d559e37c5a97b2aba27930a83.png)  
The only folder named majestic reader is too far down on the hierarchy. Comparing to the final project, the place they should be creating the new module is at the project root.

---

<div class="post-metadata">

**Author:** ![abunur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/abunur/32/109585_2.png) [@abunur](https://forums.kodeco.com/u/abunur)\
**Post date:** [October 14, 2019, 9:58pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/10 "2019-10-14T21:58:05Z")

</div>

Actually, I can’t get the starter or final projects to run. Opening them in Android Studio, it says “module not specified” and there is no module to choose from. Something seems to be missing from the project files to get the projects to work out of the box?

Also, the final project code does not match the code as per the tutorial. For example, there is a step which says:

> Open `MajesticReaderApplication` and replace `onCreate()` with the following, making sure you add all the necessary imports:

The code from this step is nowhere to be found in the final project. It seems perhaps the wrong code was submitted for the final project?

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [October 15, 2019, 2:03pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/11 "2019-10-15T14:03:26Z")

</div>

Hi @abunur thanks for the question!

I uploaded a new version of the tutorial materials that should have addressed this problem. Let us know if you’re still unable to build the project in Android Studio 3.5 or later.

Also, the `MajesticReaderApplication` class is in the `framework` package of the app module.

Thanks again!

---

<div class="post-metadata">

**Author:** ![sagarsuri](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sagarsuri/32/91485_2.png) [@sagarsuri](https://forums.kodeco.com/u/sagarsuri)\
**Post date:** [November 10, 2019, 3:29pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/12 "2019-11-10T15:29:15Z")

</div>

@macsimus @ikust  
Great article! But I am curious to know why did you use `GlobalScope` instead of `viewModelScope`?

---

<div class="post-metadata">

**Author:** ![ikust](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ikust/32/107453_2.png) [@ikust](https://forums.kodeco.com/u/ikust)\
**Post date:** [November 12, 2019, 10:35am UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/13 "2019-11-12T10:35:36Z")

</div>

Hi @sagarsuri,  
thanks for the question! I’m glad that you like the article 🙂

`viewModelScope` would be the appropriate scope to use but it was added in version 2.1.0 of `androidx.lifecycle:lifecycle-viewmodel-ktx` library which wasn’t available at the time of writing. To keep things as simple as possible we used `GlobalScope`.

---

<div class="post-metadata">

**Author:** ![sagarsuri](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sagarsuri/32/91485_2.png) [@sagarsuri](https://forums.kodeco.com/u/sagarsuri)\
**Post date:** [November 15, 2019, 5:10am UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/14 "2019-11-15T05:10:50Z")

</div>

@ikust  
Where is the right place for `di` folder to reside?

---

<div class="post-metadata">

**Author:** ![ikust](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ikust/32/107453_2.png) [@ikust](https://forums.kodeco.com/u/ikust)\
**Post date:** [November 15, 2019, 12:48pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/15 "2019-11-15T12:48:18Z")

</div>

@sagarsuri If you are referring to a folder that would hold Dependency Injection related code, the right place for it is `framework` package in the app module.

---

<div class="post-metadata">

**Author:** ![madalin](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/madalin/32/81494_2.png) [@madalin](https://forums.kodeco.com/u/madalin)\
**Post date:** [November 23, 2019, 3:06pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/16 "2019-11-23T15:06:05Z")

</div>

Nice tutorial!

I have some questions related to the graph that shows communication between the layers:

1. Why did you add arrows in both directions between layers? For example between 'Presentation layer ’ and ‘Use cases layer’ or ‘Data Layer’ and ‘Domain layer’?
2. Why there is no arrow between ‘Use cases layer’ and ‘Domain Layer’ because, for example, ‘AddBookmark’ class (from ‘interactors’ package) has direct access to ‘Bookmark’ and ‘Document’ classes from domain layer.

Thanks

---

<div class="post-metadata">

**Author:** ![ikust](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ikust/32/107453_2.png) [@ikust](https://forums.kodeco.com/u/ikust)\
**Post date:** [November 27, 2019, 4:55pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/17 "2019-11-27T16:55:28Z")

</div>

Hi,  
thank you, I’m glad that you like the tutorial!

1. I’ve added arrows in both directions to show that a lower layer requests information from a higher layer and gets a result. For example ViewModel from Presentation layer calls function from Interactor and gets a result.
2. That is correct. I wanted to note that ‘Bookmark’ and ‘Document’ classes from Domain layer are accessed through Data layer - for example AddBookmark class uses BookmarkRepository to add a new Bookmark.

---

<div class="post-metadata">

**Author:** ![borrom](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/borrom/32/81494_2.png) [@borrom](https://forums.kodeco.com/u/borrom)\
**Post date:** [December 13, 2019, 4:19pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/18 "2019-12-13T16:19:17Z")

</div>

Great tutorial, but I don’t viewModel should hold the application context,.  
If i am not wrong the viewModel should not know anything about Android framework.

---

<div class="post-metadata">

**Author:** ![ikust](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ikust/32/107453_2.png) [@ikust](https://forums.kodeco.com/u/ikust)\
**Post date:** [December 13, 2019, 4:42pm UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/19 "2019-12-13T16:42:23Z")

</div>

Hi,  
thank you, glad that you like the tutorial!

Looking at the [official documentation](https://developer.android.com/topic/libraries/architecture/viewmodel), using Application context in `ViewModel` is permitted. It is important to not reference anything that may hold a reference to the activity context since ViewModel can outlive Activity.

A quote from the documentation:

> A [`ViewModel`](https://developer.android.com/reference/androidx/lifecycle/ViewModel.html) must never reference a view, [`Lifecycle`](https://developer.android.com/reference/androidx/lifecycle/Lifecycle.html), or any class that may hold a reference to the activity context.

**Android Jetpack** even provides [`AndroidViewModel`](https://developer.android.com/reference/androidx/lifecycle/AndroidViewModel.html) which can be extended and has a reference to Application.

---

<div class="post-metadata">

**Author:** ![ruifernando](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ruifernando/32/81494_2.png) [@ruifernando](https://forums.kodeco.com/u/ruifernando)\
**Post date:** [January 5, 2020, 4:24am UTC](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272/20 "2020-01-05T04:24:06Z")

</div>

i’m just wondering, is it allow to pass 2 or more different repositories into one use case?

[Next page](https://forums.kodeco.com/t/clean-architecture-tutorial-for-android-getting-started-raywenderlich-com/78272.md?page=2)
