Setup Android new project with boilerplate code within 5 minutes using Github Template

Setup Android new project with boilerplate code within 5 minutes using Github Template

Β·

3 min read

Creating a new project from Android studio and setting up all the required boilerplate code like Base classes, utils classes, extensions (Kotlin) takes so much time. Before exploring Github repo templates , I was importing the core/base module in all new projects to set up my boilerplate code, after setting the core/base module, I'll go for setup the other required boilerplate like buildSrc module, Ktlint, Detekt, CI/CD, .gitignore, etc.

Again, this is always taking some 40-50 minutes to set up my new android project, so I decided to give Github Repo Templates a try. Github released this feature in 2019.

🧐 What is the Github repository template?

Creating a repository from a template helps you to generate a new repository with the same directory structure and files as an existing repository. You need to just click Use this Template on the main page of Github Repositories (If the repository is marked as a template by the Repo Admin).

🍴 Isn't it the same as forking the repository?

Creating a repository from a template is similar to forking a repository, but there are important differences:

  • A new fork includes the entire commit history of the parent repository, while a repository created from a template starts with a single commit.
  • Commits to a fork don't appear in your contributions graph, while commits to a repository created from a template do appear in your contribution graph.
  • A fork can be a temporary way to contribute code to an existing project while creating a repository from a template starts a new project quickly.

πŸ§‘πŸ»β€πŸ’» Android Studio Github Template

As I found this feature of Github very useful, I have decided to create an Android Template in which we are having some boilerplate code for any Android project.

Github repository github.com/happysingh23828/android-github-r..

πŸ›‘ Boilerplate code in this repository

  • BuildSrc module (for handling dependencies in one place).
  • Core module (includes Kotlin Extensions, Base classes, etc.).
  • Static tool analysis with Report generation (Ktlint, KtlintAutoFormat Detekt, Custom Detekt Lint Rules).
  • Android CI (using Github's Action workflow)
  • .gitignore for Android Studio Projects.
  • and many more to come...

πŸƒ Steps to create a new project using this Android template.

  • Step 01: Go to this repo and click on Use this template.

Screenshot 2021-02-13 at 9.10.14 AM.png

  • Step 02: Use the Owner drop-down menu, and select the account you want to own the repository.

  • Step 03: Choose repository visibility.

  • Step 03: Click Create repository from the template. Screenshot 2021-02-13 at 9.11.23 AM.png

  • Now you will have a repo with all the boilerplate code.

Screenshot 2021-02-13 at 9.32.33 AM.png

πŸ“ Additional Notes

CI is only triggered on the pull requests. If you need to change action go to android-master.yml You can edit rules for Detekt in this detekt-rule.yml.

Note: I'll encourage you to contribute to this repository to add boilerplate code that you always use in your projects, that'll help us to make more effective boilerplate code for any android project.


I hope you liked this article. If you find this article helpful then share it with everyone. Maybe it’ll help someone who needs it πŸ˜ƒ.

Thank you!