Create a new Android project in 2021

Starting from Kotlin DSL to Compose, MVVM, modularization, Hilt and so on!

Reza
3 min readMar 22, 2021

In this article we will go through all the goodies that are currently around for Android development in 2021, We will go through everything step by step, The goal is to consume Flickr’s Search API and we want to see how can we do this in a modular/testable way.

Creating the project:

So go ahead and create a new Android studio project, I will be using AS version 4.1.3 for this article.

Start by clicking on “Create new project” and then select “Empty Activity” and Name your project whatever you want and proceed and at the end click on the Finish button.

After Gradle’s sync is finished, Your new project is ready to rock!

Now we will focus on converting from traditional Groovy Gradle files to the new modern Kotlin DSL.

Add Kotlin DSL to the project:

We start by creating a folder named “buildSrc” in the project’s root folder, So to do this change project’s view type from “Android” to “Project”, Then right click on the root directory (Which will be your project’s name) then create a folder named “buildSrc”.

Then create a file named “build.gradle.kts” with the following content inside in the “buildSrc” directly which you created above:

Then we need to create these directories inside the “buildSrc” directory that we created above: “src/main/kotlin” so the structure will look like this:

Then we need to create some Kotlin objects in the directory we just created to keep the dependencies and versions

Version to configure the application will be kept here

Now we need to create a Kotlin object to keep track of versioning of our dependencies:

And now we create our actual dependencies holder in another Kotlin object:

Dependencies for the application will be kept here

Then we will create another file for keeping our Gradle plugin dependencies:

Now we just need to migrate two build.gradle files in project’s root and the app folder.

Start by renaming the build.gradle file in project’s root directory to build.gradle.kts and change it’s content to the one below:

and then let’s change the build.gradle file inside the app folder to build.gradle.kts and change it’s content to the one below:

Now we’re ready to sync gradle and see if everything should work!

In next parts we will continue with adding different modules and start implementing the actual logic bit by bit :)

Stay tuned!

Great job on making it to the end of this article! 💪

  • Follow my YouTube channel for video tutorials and tips on Android development
  • If you need help with your Android project, Book a 1:1 or a Pair-Programming meeting with me, 100% free! book a time here 🚀

If you like this article please can you do me a little favour and hit the 👏clap button as many times! I really appreciate your kindness x❤️👊

--

--