Use Supabase with Android Kotlin
Learn how to create a Supabase project, add some sample data to your database, and query the data from an Android Kotlin app.
Set up a Supabase project
Create a new project in the Supabase Dashboard.
After your project is ready, create a table in your Supabase database using the SQL Editor in the Dashboard. Use the following SQL statement to create all tables.
Create an Android app with Android Studio
Open Android Studio > New > New Android Project.
Install the Supabase client library
Import Supabase and all required dependencies. Replace the version placeholders $supabase_version
and $ktor_version
with the respective latest versions.
Install the serializable plugin
Open the build.gradle
(app), add the serialization plugin to use annotation for data parsing. Please note that the plugin version should be the same as the Kotlin version in your app.
Initialize the Supabase client
You can create a Supabase client whenever you need to perform an API call. That being said, it is recommended to use a dependency injection library like Hilt.
Create a data transfer object
Create a domain object
This kind of object will be consumed by the view.
Query data from the app
Create a repository to interact with the data source.
Get data from ViewModel inside a coroutine scope
Add the @Inject
annotation to use the repository in a ViewModel.
Observe data in a Composable