Skip to content

Commit a809f90

Browse files
Initial commit
0 parents  commit a809f90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2128
-0
lines changed

.github/pull_request_template.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Summary
2+
3+
* Provide a summary of this Pull Request.
4+
5+
## How It Was Tested
6+
7+
* Explain how you tested this change before merging.
8+
9+
## Screenshot/Gif
10+
11+
* If applicable, show off the user facing changes.

.github/workflows/android_build.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Android Build
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
11+
- name: Set Up JDK
12+
uses: actions/setup-java@v1
13+
with:
14+
java-version: 1.11
15+
16+
- name: Build Project
17+
run: ./gradlew assemble
18+
19+
- name: Run Tests
20+
run: ./gradlew test
21+
22+
- name: Lint Checks
23+
run: ./gradlew detekt ktlintCheck lint
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Android UI Tests
2+
3+
on: pull_request
4+
5+
jobs:
6+
android-test:
7+
runs-on: macos-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
12+
- name: Set Up JDK
13+
uses: actions/setup-java@v1
14+
with:
15+
java-version: 1.11
16+
17+
- name: Run Tests
18+
uses: reactivecircus/android-emulator-runner@v2
19+
with:
20+
api-level: 29
21+
script: ./gradlew app:connectedCheck

.github/workflows/danger_checks.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Danger Checks
2+
3+
on: pull_request
4+
5+
jobs:
6+
danger:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v1
11+
12+
- name: Set Up JDK
13+
uses: actions/setup-java@v1
14+
with:
15+
java-version: 1.11
16+
17+
- name: Set Up Ruby
18+
uses: actions/setup-ruby@v1
19+
with:
20+
ruby-version: 2.6
21+
22+
- name: Danger Checks
23+
run: |
24+
./gradlew dependencyUpdates
25+
gem install bundler
26+
bundle install
27+
bundle exec danger
28+
29+
env:
30+
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Rename Template
2+
3+
on: pull_request
4+
5+
jobs:
6+
rename-template:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
11+
- name: Set Up JDK
12+
uses: actions/setup-java@v1
13+
with:
14+
java-version: 1.11
15+
16+
- name: Rename & Build
17+
run: ./gradlew renameTemplate build

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild
9+
.cxx
10+
local.properties

Dangerfile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
message "Thanks @#{github.pr_author}!"
2+
3+
if github.pr_body.length == 0
4+
fail "Please provide a summary in the Pull Request description."
5+
end
6+
7+
if git.lines_of_code > 500
8+
warn "Please consider breaking up this pull request."
9+
end
10+
11+
if github.pr_labels.empty?
12+
warn "Please add labels to this PR."
13+
end
14+
15+
if git.deletions > git.insertions
16+
message "🎉 Code Cleanup!"
17+
end
18+
19+
# Notify of outdated dependencies
20+
dependencyUpdatesHeader = "The following dependencies have later milestone versions:"
21+
dependencyReportsFile = "app/build/dependencyUpdates/report.txt"
22+
23+
# Due to the formatting of this output file, we first check if there are any dependencies
24+
# by looking for a `->` arrow, then we check for the relevant headers. We do this to handle a case
25+
# where there are no app dependencies but there are Gradle dependencies.
26+
hasDependencyUpdatesHeader = File.readlines(dependencyReportsFile).grep(/#{dependencyUpdatesHeader}/).any?
27+
28+
if hasDependencyUpdatesHeader
29+
file = File.open(dependencyReportsFile, "rb").read
30+
index = file.index(dependencyUpdatesHeader)
31+
message file.slice(index..-1)
32+
end

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source "https://rubygems.org"
2+
3+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4+
5+
gem "danger"

README.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Android App Template
2+
3+
This is a GitHub template repository intended to kickstart development on an Android application. This project comes set with a handful of tools that [Adam](https://github.com/AdamMc331) finds important and relevant to every project. If you think something is missing, or feel strongly that a setup should be changed, please submit an [Issue](https://github.com/AdamMc331/AndroidAppTemplate/issues/new).
4+
5+
## Walkthrough
6+
7+
If you'd like a video walk through of this template and all it has to offer, you can find that on YouTube.
8+
9+
https://youtu.be/E0iMUWJn76E
10+
11+
## Using This Template
12+
13+
To use this template in your own project, click the "Use this template" button at the top right of the repository. Once you do, a repository will be created for your account that you can clone and use on your device.
14+
15+
To setup this repository to your needs, open the [setup.gradle](buildscripts/setup.gradle) file
16+
and tweak the `renameConfig` block to your needs. After that, you can run the `renameTemplate`
17+
gradle task to have the app module's package name and relevant strings replaced.
18+
19+
### Cleanup
20+
21+
Once you've done this, feel free to delete that [setup.gradle](buildscripts/setup.gradle) file from your project. In
22+
addition, you can remove the [template_change_test](.github/workflows/template_change_test.yml)
23+
workflow which validates the above process for the template repo itself.
24+
25+
## What's Included
26+
27+
A number of third party dependencies are included in this template. They are also documented inside the [documentation folder](/documentation). The files inside this documentation folder are written in such a way that you can keep them in your real project, to let team members read up on why dependencies are included and how they work.
28+
29+
The dependencies in the template include:
30+
31+
* [Ktlint](/documentation/StaticAnalysis.md) for formatting.
32+
* [Detekt](/documentation/StaticAnalysis.md) for code smells.
33+
* [Git Hooks](/documentation/GitHooks.md) for automatically perform static analysis checks.
34+
* [Gradle Versions Plugin](/documentation/VersionsPlugin.md) for checking all dependencies for new versions.
35+
* [GitHub Actions](/documentation/GitHubActions.md) for running continuous integration and ensuring code quality with every PR.
36+
37+
### Danger
38+
39+
This template uses [Danger](https://danger.systems) which will perform some checks against our
40+
pull requests. You can find the list of checks in the [Dangerfile](Dangerfile). In addition, we
41+
have a GitHub Actions workflow for Danger checks. In order for that to work, you'll need a
42+
Danger API key setup in your GitHub secrets. Info on this can be found [here](https://www.jessesquires.com/blog/2020/04/10/running-danger-on-github-actions/).
43+
44+
### Templates
45+
46+
There are also templates within this template. This repo comes shipped with a [Pull Request Template](/.github/pull_request_template.md) that will help you and your team write organized and detailed pull request descriptions.
47+
48+
## Dependency Setup
49+
50+
You may notice that dependencies are set up in a very specific way. Each of the tools has its own Gradle file in the [buildscripts folder](/buildscripts). This is by design so that if you chose to have a multi module project, these dependencies can easily be shared between them. This is already configured inside our root `build.gradle` file, by applying to each sub project:
51+
52+
```groovy
53+
subprojects {
54+
apply from: "../buildscripts/ktlint.gradle"
55+
apply from: "../buildscripts/detekt.gradle"
56+
apply from: "../buildscripts/versionsplugin.gradle"
57+
}
58+
```
59+
60+
In addition, there is a [versions.gradle](/buildscripts/versions.gradle) file which includes the version numbers of all dependencies used inside the app module. The benefit of moving them here, is that if any dependencies are shared between two modules, we only have to update the version number in one spot. As an added bonus, each dependency version also has a comment linking to the release page, so you can quickly reference to see what's changed.
61+

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
}
5+
6+
android {
7+
compileSdk 31
8+
9+
defaultConfig {
10+
applicationId "template.app.id"
11+
minSdk 21
12+
targetSdk 31
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
vectorDrawables {
18+
useSupportLibrary true
19+
}
20+
}
21+
22+
buildTypes {
23+
release {
24+
minifyEnabled false
25+
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
26+
}
27+
}
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
32+
kotlinOptions {
33+
jvmTarget = "1.8"
34+
useIR = true
35+
}
36+
buildFeatures {
37+
compose true
38+
}
39+
composeOptions {
40+
kotlinCompilerExtensionVersion rootProject.ext.versions.compose
41+
kotlinCompilerVersion kotlinVersion
42+
}
43+
packagingOptions {
44+
resources {
45+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
46+
}
47+
}
48+
}
49+
50+
dependencies {
51+
52+
implementation "androidx.core:core-ktx:$rootProject.ext.versions.ktxCore"
53+
implementation "androidx.appcompat:appcompat:$rootProject.ext.versions.appCompat"
54+
implementation "com.google.android.material:material:$rootProject.ext.versions.material"
55+
implementation "androidx.compose.ui:ui:$rootProject.ext.versions.compose"
56+
implementation "androidx.compose.material:material:$rootProject.ext.versions.compose"
57+
implementation "androidx.compose.ui:ui-tooling-preview:$rootProject.ext.versions.compose"
58+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$rootProject.ext.versions.lifecycle"
59+
implementation "androidx.activity:activity-compose:$rootProject.ext.versions.activityCompose"
60+
testImplementation "junit:junit:$rootProject.ext.versions.junit"
61+
androidTestImplementation "androidx.test.ext:junit:$rootProject.ext.versions.androidxTest"
62+
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.ext.versions.espresso"
63+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$rootProject.ext.versions.compose"
64+
debugImplementation "androidx.compose.ui:ui-tooling:$rootProject.ext.versions.compose"
65+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="template">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.AppTheme">
12+
13+
<activity
14+
android:name="template.MainActivity"
15+
android:exported="true"
16+
android:theme="@style/Theme.AppTheme.NoActionBar">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package template
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.material.MaterialTheme
7+
import androidx.compose.material.Surface
8+
import androidx.compose.material.Text
9+
import androidx.compose.runtime.Composable
10+
import androidx.compose.ui.tooling.preview.Preview
11+
import template.theme.TemplateTheme
12+
13+
class MainActivity : ComponentActivity() {
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
setContent {
17+
TemplateTheme {
18+
// A surface container using the 'background' color from the theme
19+
Surface(color = MaterialTheme.colors.background) {
20+
Greeting("Android")
21+
}
22+
}
23+
}
24+
}
25+
}
26+
27+
@Composable
28+
fun Greeting(name: String) {
29+
Text(text = "Hello $name!")
30+
}
31+
32+
@Preview(showBackground = true)
33+
@Composable
34+
fun DefaultPreview() {
35+
TemplateTheme {
36+
Greeting("Android")
37+
}
38+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@file:Suppress("MagicNumber")
2+
3+
package template.theme
4+
5+
import androidx.compose.ui.graphics.Color
6+
7+
val Purple200 = Color(0xFFBB86FC)
8+
val Purple500 = Color(0xFF6200EE)
9+
val Purple700 = Color(0xFF3700B3)
10+
val Teal200 = Color(0xFF03DAC5)

0 commit comments

Comments
 (0)