My Base Project Setup for starting any project in Android (XML)

Bharat Kumar
3 min readFeb 22, 2023

I am writing this article to tell you about my base project setup that I use to work efficiently.

Generally I don’t start a project by creating a new project from android studio NO. I have created a Base project I clone that change the package and app names update the dependencies and start with that so that I don't have to work much.

So today I just wanted to share all that with you guys how do i do it.

Here is the link of my project which I use

I have 2 types one is which has a bottom navigation another with navigation drawer because both are mostly common in any projects.

Now lets start with my package structure. Here is how it looks -

I have data, di(Dependency Injection), ui and utils packages which contains the respective classes and files.

First Lets see what do I have in Data layer

Here I have persistence package for things like shared preference and Data store. I have a LocalModel class just for example as I wanted to add ROOM also but not every project needs so I didn’t.

In the remote package I have the API interfaces as many as I need, all the repositories and requests and response model classes.

If you open the project you can see I already have code of saving token in Encrypted shared preferences.

Next lets move on to UI layer —

I have here packages for activities, adapter, base and fragment.

Base is for the Base abstract classes I have created to use databinding without writing all that code repeatedly. You can just look the fragments and activities to see how to use it. Its really simple.

Then we have activity for all activities although you should have only one activity and use navigation components with remaining as fragments.

As guessed we have fragments and their respective viewmodels in the fragments package and Recycler adapter in adapters one

Then we have DI package

As i am using HILT here I have all the dependencies here which i want to Inject like Retrofit, OK-HTTP etc. In the AppModule and in the ApiModule i am providing the Interfaces of retrofit for API calling.

At last the most important one Utils package

This is the most important package which I use in every project.

Lets start with the network package this is used to make my network calls a lot easier inspired from Jaewoong Eums sandwich library we have this module to make API calling efficient. I can’t do into the details of each file but I'll let you know the important parts which you may need.

In the handle Api we have the main thing which handles error exception and success. In the interceptors we have auth interceptor for token passing.

Then I have downloader package which contains files to easily download any file and we have many useful fragment extensions and much more.

That is all. If you want to see how it works please clone the project and check you will understand it much clearly. I have also done fake API calls so that you can understand how is it done.

Hope you like it. Enjoy your development.

--

--