This is a simple to-do list application demonstrating the use of the Kotlin Multiplatform SDK's Android package in an Android Kotlin project with Supabase.
To run this demo, you need a Supabase and PowerSync project. Detailed instructions for integrating PowerSync with Supabase can be found in the integration guide.
Follow this guide to:
- Create and configure a Supabase project.
- Create a new PowerSync instance, connecting to the database of the Supabase project. See instructions here.
- Deploy Sync Streams.
This demo uses Sync Streams with auto-subscribed streams to sync data. Deploy the following configuration:
config:
edition: 3
streams:
all_lists:
priority: 1
auto_subscribe: true
query: SELECT * FROM lists WHERE owner_id = auth.user_id()
list_items:
auto_subscribe: true
query: SELECT todos.* FROM todos INNER JOIN lists ON todos.list_id = lists.id WHERE lists.owner_id = auth.user_id()```Giving lists a higher priority allows updates to be synced before all items have been received.
- Clone this repo:
git clone https://github.com/powersync-ja/powersync-kotlin.git - Open
powersync-kotlin/in Android Studio. - Sync the project with Gradle (this should happen automatically, or choose File > Sync project with Gradle Files).
- Insert your Supabase project URL, Supabase Anon Key, and PowerSync instance URL into the
demos/android-supabase-todolist/local.propertiesfile:
# local.properties
sdk.dir=/path/to/android/sdk
# Enter your PowerSync instance URL
POWERSYNC_URL=https://foo.powersync.journeyapps.com
# Enter your Supabase project's URL and public anon key (Project settings > API)
SUPABASE_URL=https://foo.supabase.co
SUPABASE_ANON_KEY=fooChoose a run configuration for the Android app in Android Studio and run it.
- Add
jitpackas a repository to yoursettings.gradle.ktsso that the underlying android sqlite package can be downloaded:
dependencyResolutionManagement {
repositories {
maven("https://jitpack.io")
...
}
}- Add the PowerSync SDK to your project by adding the following to your
build.gradle.ktsfile:
dependencies {
implementation("com.powersync:core-android:$powersyncVersion")
...
}If you want to use the Supabase Connector, also add the following to dependencies:
dependencies {
implementation("com.powersync:connector-supabase:$powersyncVersion")
...
}