Skip to content

Commit ad7ecd3

Browse files
committed
Add README, LICENSE and // TODO to indicate configuration priority; upgrade android gradle plugin version
1 parent 6cbf4f7 commit ad7ecd3

9 files changed

Lines changed: 196 additions & 23 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Engine Bai
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 166 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,167 @@
1-
## File Structures
2-
* `/base` module:
3-
* Responsibility: define the base, common and utilities classes.
4-
* It can be updated by merging base repository, and will not affect the project modules.
5-
* `/app` module:
6-
* Responsibility: define all the features in your app.
7-
* Define `applicationId` as app package name.
8-
* Include all resources that app used. (including strings, colors, dimensions, drawables.)
9-
10-
## Dependencies
11-
* `/app` include `/base` serves as common library that the whole project used.
12-
13-
## Don't do
14-
Don't add anything to the module other than `/base`, since other modules will change the package to feature, and it will break the merge.
1+
![Language](https://img.shields.io/badge/language-kotlin-blue?logo=kotlin) ![License](https://img.shields.io/badge/License-MIT-brightgreen)
2+
3+
The `Base` project provides a Android app project template that includes the base modules/classes, setups for **Gradle Kotlin DSL** and eliminates boilerplate code.
4+
5+
It helps you to quickly create a well configured Android starter application with the most popular libraries (Ex: Android Architecuture Component, Retrofit/OkHttp, RxJava, Logging...etc.). It creates and configures your project for you. Just focus on code development!
6+
7+
## Setup
8+
1. Just click on [![Clone this template](https://img.shields.io/badge/-Clone%20template-brightgreen)](https://github.com/enginebai/Base/generate) button to create a new repo starting from this template. Or you can clone this project by `git clone git@github.com:enginebai/Base.git` .
9+
2. Set your application ID in `Versions.kt`
10+
3. Set the package name in `AndroidManifest.xml` file of `:app` module .
11+
4. Select `com.enginebai.project` directory in "Project" tool window and rename package for your app.
12+
5. Create your application class which extends `BaseApplication` in `:app` module, implement abstract methods and add to `AndroidManifest.xml` file.
13+
6. Specify your retrofit base URL in `NetworkModule.kt` file.
14+
7. Start to design your main layout xml file `fragment_main.xml` and fragment class.
15+
8. That's all. Start your app development journey now 🎉.
16+
17+
## Good Practices
18+
* Add all dependencies version in `Versions.kt`
19+
20+
```kotlin
21+
object Versions {
22+
const val kotlin = "1.3.50"
23+
const val awesomeLibrary = "x.y.z"
24+
...
25+
}
26+
```
27+
* Add all 3rd-party dependencies in `Dependencies.kt`
28+
29+
```kotlin
30+
object Dependencies {
31+
const val rxJava = "io.reactivex.rxjava2:rxjava:${Versions.rxJava}"
32+
// TODO: add standalone dependency here!
33+
...
34+
35+
object Kotlin {
36+
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
37+
const val stdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
38+
}
39+
40+
// TODO: add inner object for sub-modules of library
41+
object AndroidX {
42+
...
43+
}
44+
...
45+
}
46+
```
47+
* Always import dependency from `Dependencies.kt` in `build.gradle.kts` file.
48+
49+
```kotlin
50+
dependencies {
51+
implementation(Dependencies.Glide.core)
52+
"kapt"(Dependencies.Glide.compiler)
53+
implementation(project(":base"))
54+
// TODO: add by using dependency imported from `Dependencies.kt` file
55+
...
56+
}
57+
```
58+
59+
* Configure android build script in `Config.kt`.
60+
61+
```kotlin
62+
fun Project.configAndroid() = this.extensions.getByType<BaseExtension>().run {
63+
compileSdkVersion(Versions.Android.sdk)
64+
defaultConfig {
65+
minSdkVersion(Versions.Android.minSdk)
66+
targetSdkVersion(Versions.Android.sdk)
67+
versionCode = Versions.App.versionCode
68+
versionName = Versions.App.versionName
69+
// TODO: add your configurations
70+
...
71+
}
72+
...
73+
}
74+
```
75+
76+
It's equalivent to the old way `android { ... }` block in `build.gradle` file
77+
```groovy
78+
android {
79+
compileSdkVersion 21
80+
buildToolsVersion "21.1.2"
81+
defaultConfig {
82+
applicationId "com.enginebai.moviehunt"
83+
// TODO: add your configurations
84+
...
85+
}
86+
...
87+
}
88+
```
89+
90+
91+
* Add all configuration variables inside `Config` object in `Config.kt`, and add `buildConfigField(...)` to include.
92+
93+
```kotlin
94+
object Config {
95+
const val API_ROOT = "\"https://api.themoviedb.org/3/\""
96+
const val IMAGE_API_ROOT = "\"https://image.tmdb.org/t/p/\""
97+
// TODO: add your constants here, make sure to add extra double quotes for string value.
98+
}
99+
100+
fun Project.configAndroid() = this.extensions.getByType<BaseExtension>().run {
101+
compileSdkVersion(Versions.Android.sdk)
102+
defaultConfig {
103+
...
104+
105+
buildConfigField("String", "API_ROOT", Config.API_ROOT)
106+
buildConfigField("String", "IMAGE_API_KEY", Config.IMAGE_API_ROOT)
107+
// TODO: add your varialbes here imported from `Config` object
108+
...
109+
}
110+
...
111+
}
112+
```
113+
114+
* Add the common dependencies that share between modules to `Dependencies.kt`
115+
116+
```kotlin
117+
fun Project.importCommonDependencies() {
118+
dependencies {
119+
...
120+
implementation(Dependencies.material)
121+
// TODO: add your dependencies
122+
..
123+
}
124+
}
125+
```
126+
127+
> **Note:** Remember to perform Gradle Sync to apply your changes when updating any files in `buildSrc`.
128+
129+
## Modules Structure
130+
* `:base` module: It defines the base, common and utilities classes.
131+
* `:app` module: That's your app module, just like a normal Android app project. You puts all resources that app used, including strings, colors, dimensions, drawables. Or you can create `:common` modules for that if you use multi-modules project.
132+
133+
> **Note**: Don't put the resources inside `:base` module since it can be updated from remote repo, please treat `:base` module as library.
134+
135+
## Included Libraries
136+
* [Android Architecture Components](https://developer.android.com/topic/libraries/architecture), part of Android Jetpack for give to project a robust design, testable and maintainable.
137+
* [Retrofit](https://github.com/square/retrofit) / [OkHttp](https://github.com/square/okhttp), Square open-source RESTful API and http client.
138+
* [RxJava](https://github.com/ReactiveX/RxJava/) / [RxAndroid](https://github.com/ReactiveX/RxAndroid), reactive programming for JVM.
139+
* [Koin](https://github.com/InsertKoinIO/koin), kotlin light-weight dependency injection.
140+
* [Timber](https://github.com/JakeWharton/timber), for logging.
141+
* [Epoxy](https://github.com/airbnb/epoxy), for RecyclerView complex view layout.
142+
143+
## LICENSE
144+
145+
```
146+
Copyright (c) 2020 Engine Bai
147+
148+
Permission is hereby granted, free of charge, to any person obtaining a copy
149+
of this software and associated documentation files (the "Software"), to deal
150+
in the Software without restriction, including without limitation the rights
151+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
152+
copies of the Software, and to permit persons to whom the Software is
153+
furnished to do so, subject to the following conditions:
154+
155+
The above copyright notice and this permission notice shall be included in all
156+
copies or substantial portions of the Software.
157+
158+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
159+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
160+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
161+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
162+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
163+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
164+
SOFTWARE.
165+
```
166+
15167

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- TODO: change the package name-->
2+
<!-- TODO: 2. change the package name-->
33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
44
package="com.enginebai.project">
55

6-
<!-- TODO: define your application name -->
6+
<!-- TODO: 4. define your application name -->
77
<application
88
android:allowBackup="true"
99
android:icon="@mipmap/ic_launcher"

app/src/main/java/com/enginebai/project/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.enginebai.project
22

33
import com.enginebai.base.view.BaseActivity
44

5-
// TODO: rename the package for your project
5+
// TODO: 3. rename the package for your project
66
class MainActivity : BaseActivity() {
77
override fun getLayoutId() = R.layout.activity_main
88

app/src/main/res/layout/fragment_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
android:layout_width="match_parent"
55
android:layout_height="match_parent">
66

7-
<!-- TODO: start your main layout -->
7+
<!-- TODO: 6. start your main layout -->
88

99
</androidx.constraintlayout.widget.ConstraintLayout>

base/src/main/java/com/enginebai/base/di/NetworkModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ val networkModule = module {
2727
single<Converter.Factory> { GsonConverterFactory.create() }
2828
single<CallAdapter.Factory> { RxJava2CallAdapterFactory.create() }
2929
single<Retrofit> {
30-
// TODO: specify the base URL
30+
// TODO: 5. specify the base URL
3131
Retrofit.Builder()
3232
.baseUrl("")
3333
.addCallAdapterFactory(get())

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ plugins {
1919

2020
dependencies {
2121
// Depend on the android gradle plugin, since we want to access it in our plugin
22-
implementation("com.android.tools.build:gradle:3.5.1")
22+
implementation("com.android.tools.build:gradle:4.0.0")
2323

2424
// Depend on the kotlin plugin, since we want to access it in our plugin
2525
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50")

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object Versions {
2525
}
2626

2727
object App {
28-
// TODO: name your android ID, version information
29-
const val id = ""
28+
// TODO: 1. name your android ID, version information
29+
const val id = "com.enginebai.test"
3030
const val versionCode = 1
3131
const val versionName = "1.0.0"
3232
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

0 commit comments

Comments
 (0)