‫Hello developers, and welcome back.
‫In this video we're going to create our project and add the required dependencies for it.
‫Open Android Studio, select new project Empty Views activity and here name it as Contacts Manager app.
‫Select Language Kotlin and click finish.
‫Then we need to add the required dependencies for this project.
‫Go to developer.android.com slash jetpack slash Android slash releases slash room, or you can simply
‫search for room database dependency and you can get the stable release 2.6.1.
‫Here we need to add at first the room version and the implementation for it.
‫So go to build.gradle dot css file and search for dependencies.
‫And here paste it in the dependencies.
‫So this is our room database version 2.6 and its dependency.
‫Then we need to add an annotation preprocessor dependency for our room database.
‫Since room database uses annotations in all its parts, we need to add an annotation processor in Android
‫development annotation processor Capt, Kotlin annotation processing tool and KSP Kotlin symbol processing
‫are tools used for annotation processing.
‫They play a crucial role in development workflow when working with libraries that leverage annotations
‫that uses annotations such as room database.
‫So the room database uses annotations, and for that we need to add one of these annotation processors.
‫At first, let's discuss these processors and the why we need and where we need to use them.
‫Annotation processor is a Java based annotation processing tool.
‫It's used in projects where the primary language is Java.
‫This tool processes annotations during the compilation phase that generates code based on those annotations.
‫Room database initially used annotation processor to generate database related code.
‫Capt Kotlin annotation processing tool Capt is the Kotlin specific counterpart to annotation processor.
‫It allows annotation processing for Kotlin code.
‫When using Kotlin in Android projects, you typically replace annotation processor with Capt for libraries
‫that provide Kotlin support room database.
‫Being a part of Android, jetpack has added support for Kotlin and developers are encouraged to use
‫Capt instead of annotation processor when working with room in Kotlin projects.
‫KSP is a newer annotation processing tool introduced by JetBrains, the creators of Kotlin and the Android
‫Studio.
‫It's designed to be more efficient and faster than Capt, offering improved performance during compilation.
‫KSP is the recommended annotation processing tool for Kotlin, starting from Kotlin 1.5.0.
‫For that, I'll use this annotation processor.
‫You can use Capt because we created our project in Kotlin, so you can use either Capt or KSP.
‫KSP is faster than Cat, so I'll use it here and we need to add this plugin.
‫You can go to Developer.android.com slash build slash migrate to KSP.
‫And this is a newer tool and very fast compared to Capt.
‫And here I'll select Kotlin, add the dependency or the plugin copy.
‫And you can see it's at the level of the project.
‫So it's not in this Build.gradle file.
‫It's in this project level.
‫So paste it here and click sync.
‫Now then we need to add the dependency and enable it in the module level.
‫Copy this ID and go to Build.gradle CSS file and scroll up and paste it here.
‫Then I need to add the KSP annotation for the room or KSP dependency.
‫Also, you can get it from the room database here like this and copy it to the dependencies.
‫Sync the project.
‫And congratulations!
‫We've added the room database with its annotation processor.
‫One last thing we need to add with the room database is the coroutines.
‫So I'll copy this implementation Android ECS with the coroutines.
‫And here I'll paste it.
‫Also we need to add the coroutines dependency.
‫So go to Developer.android.com slash Kotlin slash coroutines or simply search for Kotlin coroutines.
‫Dependency in Android.
‫Coroutines help to manage long running tasks that might otherwise block the main thread and cause your
‫app to become unresponsive.
‫And since we are dealing with databases, the room database, I'm going to use the coroutines to simplify
‫code that executes asynchronously in the database.
‫So we're going to add, remove, update, delete and the query database asynchronously.
‫For that purpose I'm going to use the the coroutines.
‫And by the way I have a section called coroutines.
‫I want from you to jump to it and learn about coroutines in deep.
‫Or you can simply follow my my Room database section and then move to the coroutines.
‫I'll copy this dependency and don't worry, I'll lecture everything regarding the keys and the concepts
‫of the coroutines that we're going to use with the room database.
‫Copy and paste this and replace it to 1.7.
‫This the coroutines dependency.
‫And this is for room with coroutines.
‫This is the annotation processor and this is the room database.
‫Click sync now and our project is ready to use room database.
‫I'm going to add later on the other dependencies step by step.