This is an Android-Studio Template for CleanArchitecture Template & Kotlin
This repository is made with reference to Android-Studio-MVP-template. So, the repository configuration is similar.
It is inspired Android-CleanArchitecture and android-architecture-component
V2.X is supported androidX ONLY!!.
So, if your project don't migrate to androidX,please do it first!!
Or,please use V1.X templates
Here's the hierarchy it follows:
com.company.app
+--- data
| - datasource
| - entity
|
+--- domain
|
+--- presenter
|
+--- utils
| +--- annotations
| | - ActivityScope
| | - ViewModelKey
| |
| +--- commons
| | - BasePresenter
| | - BaseView
| | - DefaultDisposableObserver
| | - ExecutionThreads
| | - InputOnlyUseCase
| | - IoUseCase
| | - OutputOnlyUseCase
| | - SimpleUseCase
| | - UseCase
| +--- di
| | - ApiModules
| | - ApplicationModule
| | - BindingModules
| | - Injectable
| | - RepositoryModules
| | - RootComponent
| | - ViewModelFactory
| |
| +--- exceptions
| |
| +--- extensions
| - Observable
|
| - MainApplication
res
+--- layout
| - base_activity.xml
You must satisfy the following conditions.
- Kotlin(Recommended to use Android-Studio 3.3)
- Dagger2 for dependency injection
- RxJava2 for Asynchronous processing.
- Kotlin Android Extensions (Default Support)
- Dagger2
- RxJava2
- Realm
- ConstraintLayout
- Retrofit2
- Swagger
- android-ktx
- DataBinding
- ViewModel
- Spek1.X
- Mockito
- robolectric
- Assert-J
- If you have a standard Android Studio installation:
Just run the install script at the root of this repository:
./install.sh
- Manual installation:
Just copy all 5 directories
BaseCleanArchitectureTemplateKotlin
DataTemplateKotlin
DomainTemplateKotlin
PresenterActivityTemplateKotlin
PresenterFragmentTemplateKotlin
PresenterServiceTemplateKotlin
PresenterBroadcastReceiverTemplateKotlin
and paste to $ANDROID_STUDIO_FOLDER$/Contents/plugins/android/lib/templates/activities/
Just copy all 5 directories
BaseCleanArchitectureTemplateKotlin
DataTemplateKotlin
DomainTemplateKotlin
PresenterActivityTemplateKotlin
PresenterFragmentTemplateKotlin
PresenterServiceTemplateKotlin
PresenterBroadcastReceiverTemplateKotlin
and paste to $ANDROID_STUDIO_FOLDER$\plugins\android\lib\templates\activities\
First of all, create the base hierarchy and classes using CleanArchitectureTemplate
from the root package folder. This needs to be done only once per project:
Or if you create a new project, please select .CleanArchitectureTemplate
on this screen
Android Studio 3.3 maybe unsupport to add original Template to Create a new Project Selection..
Next, you set project config.
- Application Class Name -> Set Root ApplicationClass Name
- Create kotlin src dir? -> Please check if you have not previously created the kotlin folder
- Need Realm? -> Please check this when using Realm
- Need Retrofit2? -> Please check this when using Retrofit2
- Use Swagger? -> Please check this if the Retrofit API was created by Swagger(RxJava2 used)
When all settings are completed click the Finish button!!
Completed to generate Base classes, it will added FIXME_merge_to_build.gradle
files.
Open these files and merge to original build.gradle
files.
End of merge, execute gradle sync!!
Some templates need your work.
This template create data-layer template.
This template will add DataSourceClass and DataRepositoryClass.
And then, please see DataSourceClass.The following notice is written there.
/* FIXME MUST add below method to RepositoryModules */
// @Binds abstract fun bindSomeDataSource(repository: SomeRepository):SomeDataSource
So, Copy @Binds abstract fun bindSomeDataSource(repository: SomeRepository):SomeDataSource
to RepositoryModules
This Layer Provide Interface to domain.
This template create domain-layer template.
This template will add IoUsecaseClass or InputOnlyUseCaseClass or OutputOnlyUseCaseClass or SimpleUseCaseClass.
This Layer Provide Bussiness Logic and connect DataLayer to PresentationLayer.
This template create presenter-layer template.
This template will add ContractClass, ModuleClass, PresenterViewModelClass, ActivityClass, FragmentClass and fragment.xml.
And then, please see ModuleClass. The following notice is written there.
/* FIXME MUST add below method to BindingModules */
// @ContributesAndroidInjector(modules = [SomeModule::class]) @ActivityScope abstract fun contributeSomeActivityInjector(): SomeActivity
So, Copy @ContributesAndroidInjector(modules = [SomeModule::class]) @ActivityScope abstract fun contributeSomeActivityInjector(): SomeActivity
to BindingModules
.
This Layer Provides UserInterface(Activity & Fragment). And presenterClass communicate domain-layer.
This template create presenter-layer template.
This template will add ContractClass, PresenterViewModelClass, FragmentClass and fragment.xml.
And then, please see FragmentClass. The following notice is written there.
/* FIXME MUST add below method to Parent Activity's Module */
// @Binds @IntoMap @ViewModelKey(SomePresenterViewModel::class) abstract fun bindSomePresenterViewModel(viewModel: SomePresenterViewModel): ViewModel
// @ContributesAndroidInjector abstract fun contributeSomeFragment():SomeFragment
So, Copy @Binds @IntoMap @ViewModelKey(SomePresenterViewModel::class) abstract fun bindSomePresenterViewModel(viewModel: SomePresenterViewModel): ViewModel
and @ContributesAndroidInjector abstract fun contributeSomeFragment():SomeFragment
to Parent activity's module
.
This Layer Provides UserInterface(Fragment). And presenterClass communicate domain-layer.
This template create presenter-layer template.
This template will add ContractClass, ModuleClass, PresenterClass and ServiceClass.
And then, please see ModuleClass. The following notice is written there.
/* FIXME MUST add below method to BindingModules */
// @ContributesAndroidInjector(modules = [SomeServiceModule::class]) abstract fun contributeSomeServiceServiceInjector(): SomeServiceService
So, Copy @ContributesAndroidInjector(modules = [SomeServiceModule::class]) abstract fun contributeSomeServiceServiceInjector(): SomeServiceService
to BindingModules
.
This Layer Provides UserInterface(Service). And presenterClass communicate domain-layer.
This template create presenter-layer template.
This template will add ContractClass, ModuleClass, PresenterClass and ReceiverClass.
And then, please see ModuleClass. The following notice is written there.
/* FIXME MUST add below method to BindingModules */
// @ContributesAndroidInjector(modules = [SomeReceiverModule::class]) abstract fun contributeSomeReceiverReceiverInjector(): SomeReceiverReceiver
So, Copy @ContributesAndroidInjector(modules = [SomeReceiverModule::class]) abstract fun contributeSomeReceiverReceiverInjector(): SomeReceiverReceiver
to BindingModules
.
This Layer Provides UserInterface(BroadCastReceiver). And presenterClass communicate domain-layer.
Very simple example is in the Example folder.
Qiitaに以下の記事を公開したのでそちらを参照
「Kotlin用のCleanArchitectureのテンプレート作ったよ!」
- https://github.com/benoitletondor/Android-Studio-MVP-template
- https://github.com/android10/Android-CleanArchitecture
- https://github.com/googlesamples/android-architecture-components
- http://y-anz-m.blogspot.jp/2018/04/reified-lazy-intent-extra.html
Copyright 2017- kiuchi keisuke
Licensed 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.