Skip to content

Commit 64db232

Browse files
DominicGBauerDominicGBauerbenitavstevensJourney
authored
feat: add native android supabase todolist demo (#56)
* feat: add android demo * chore: gradle deps * chore: gradle deps * chore: pr reverts * chore: pr reverts * docs: improve readme * docs: add demo entry * docs: update readme Co-authored-by: benitav <[email protected]> * Update demos/android-supabase-todolist/README.md Co-authored-by: stevensJourney <[email protected]> * docs: update readme to use android package --------- Co-authored-by: DominicGBauer <[email protected]> Co-authored-by: benitav <[email protected]> Co-authored-by: stevensJourney <[email protected]>
1 parent a886118 commit 64db232

File tree

70 files changed

+2166
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2166
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Demo applications are located in the [`demos/`](./demos) directory. See their re
3737
- [demos/hello-powersync](./demos/hello-powersync/README.md): A minimal example demonstrating the use of the PowerSync Kotlin Multiplatform SDK and the Supabase connector.
3838

3939
- [demos/supabase-todolist](./demos/supabase-todolist/README.md): A simple to-do list application demonstrating the use of the PowerSync Kotlin Multiplatform SDK and the Supabase connector.
40+
-
41+
- [demos/android-supabase-todolist](./demos/android-supabase-todolist/README.md): A simple to-do list application demonstrating the use of the PowerSync Kotlin Multiplatform SDK and the Supabase connector in an Android application.
4042

4143
## Current Limitations / Future work
4244

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# PowerSync + Supabase Android Demo: Todo List App
2+
3+
This is a simple to-do list application demonstrating the use of the Kotlin Multiplatform SDK's Android package in an [Android Kotlin](https://kotlinlang.org/docs/android-overview.html) project with [Supabase](https://supabase.com/).
4+
5+
## Set up your Supabase and PowerSync project
6+
7+
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](https://docs.powersync.com/integration-guides/supabase).
8+
9+
Follow this guide to:
10+
1. Create and configure a Supabase project.
11+
2. Create a new PowerSync instance, connecting to the database of the Supabase project. See instructions [here](https://docs.powersync.com/integration-guides/supabase-+-powersync#connect-powersync-to-your-supabase).
12+
3. Deploy sync rules.
13+
14+
## Configure project in Android Studio
15+
16+
1. Clone this repo: ```git clone https://github.com/powersync-ja/powersync-kotlin.git```
17+
2. Open `powersync-kotlin/demos/android-supabase-todolist` in Android Studio.
18+
3. Sync the project with Gradle (this should happen automatically, or choose File > Sync project with Gradle Files).
19+
4. Insert your Supabase project URL, Supabase Anon Key, and PowerSync instance URL into the `local.properties` file:
20+
21+
```bash
22+
# local.properties
23+
sdk.dir=/path/to/android/sdk
24+
25+
# Enter your PowerSync instance URL
26+
POWERSYNC_URL=https://foo.powersync.journeyapps.com
27+
# Enter your Supabase project's URL and public anon key (Project settings > API)
28+
SUPABASE_URL=https://foo.supabase.co
29+
SUPABASE_ANON_KEY=foo
30+
```
31+
32+
## Run the app
33+
34+
Choose a run configuration for the Android app in Android Studio and run it.
35+
36+
## To include PowerSync in your own Android app make sure to do the following:
37+
38+
1. Add `jitpack` as a repository to your `settings.gradle.kts` so that the underlying android sqlite package can be downloaded:
39+
40+
```gradle
41+
dependencyResolutionManagement {
42+
repositories {
43+
maven("https://jitpack.io")
44+
...
45+
}
46+
}
47+
```
48+
49+
2. Add the PowerSync SDK to your project by adding the following to your `build.gradle.kts` file:
50+
51+
```kotlin
52+
53+
dependencies {
54+
implementation("com.powersync:core-android:$powersyncVersion")
55+
...
56+
}
57+
```
58+
59+
If you want to use the Supabase Connector, also add the following to `dependencies`:
60+
61+
```kotlin
62+
dependencies {
63+
implementation("com.powersync:connector-supabase:$powersyncVersion")
64+
...
65+
}
66+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import java.util.Properties
2+
3+
plugins {
4+
alias(libs.plugins.android.application)
5+
alias(libs.plugins.jetbrains.kotlin.android)
6+
alias(libs.plugins.sqldelight)
7+
}
8+
9+
val localProperties = Properties()
10+
val localPropertiesFile = rootProject.file("local.properties")
11+
if (localPropertiesFile.exists()) {
12+
localPropertiesFile.inputStream().use { localProperties.load(it) }
13+
}
14+
15+
fun getLocalProperty(key: String, defaultValue: String): String {
16+
return localProperties.getProperty(key, defaultValue)
17+
}
18+
19+
android {
20+
namespace = "com.powersync.androidexample"
21+
compileSdk = 34
22+
23+
buildFeatures {
24+
buildConfig = true
25+
}
26+
27+
defaultConfig {
28+
applicationId = "com.powersync.androidexample"
29+
minSdk = 24
30+
targetSdk = 34
31+
versionCode = 1
32+
versionName = "1.0"
33+
34+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
35+
vectorDrawables {
36+
useSupportLibrary = true
37+
}
38+
39+
buildConfigField("String", "SUPABASE_URL", "\"${getLocalProperty("SUPABASE_URL", "")}\"")
40+
buildConfigField("String", "SUPABASE_ANON_KEY", "\"${getLocalProperty("SUPABASE_ANON_KEY", "")}\"")
41+
buildConfigField("String", "POWERSYNC_URL", "\"${getLocalProperty("POWERSYNC_URL", "")}\"")
42+
}
43+
44+
buildTypes {
45+
release {
46+
isMinifyEnabled = false
47+
proguardFiles(
48+
getDefaultProguardFile("proguard-android-optimize.txt"),
49+
"proguard-rules.pro"
50+
)
51+
}
52+
}
53+
compileOptions {
54+
sourceCompatibility = JavaVersion.VERSION_1_8
55+
targetCompatibility = JavaVersion.VERSION_1_8
56+
}
57+
kotlinOptions {
58+
jvmTarget = "1.8"
59+
}
60+
buildFeatures {
61+
compose = true
62+
}
63+
composeOptions {
64+
kotlinCompilerExtensionVersion = "1.5.1"
65+
}
66+
packaging {
67+
resources {
68+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
69+
}
70+
}
71+
}
72+
73+
dependencies {
74+
implementation(libs.androidx.core.splashscreen)
75+
implementation(libs.androidx.core.ktx)
76+
implementation(libs.androidx.lifecycle.runtime.ktx)
77+
implementation(libs.androidx.activity.compose)
78+
implementation(platform(libs.androidx.compose.bom))
79+
implementation(libs.androidx.ui)
80+
implementation(libs.androidx.ui.graphics)
81+
implementation(libs.androidx.ui.tooling.preview)
82+
implementation(libs.androidx.material3)
83+
testImplementation(libs.junit)
84+
androidTestImplementation(libs.androidx.junit)
85+
androidTestImplementation(libs.androidx.espresso.core)
86+
androidTestImplementation(platform(libs.androidx.compose.bom))
87+
androidTestImplementation(libs.androidx.ui.test.junit4)
88+
debugImplementation(libs.androidx.ui.tooling)
89+
debugImplementation(libs.androidx.ui.test.manifest)
90+
implementation("com.powersync:core")
91+
implementation("com.powersync:connector-supabase")
92+
implementation("com.powersync:compose")
93+
implementation(libs.uuid)
94+
implementation(libs.kermit)
95+
implementation(libs.androidx.material.icons.extended)
96+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.powersync.androidexample
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.powersync.androidexample", appContext.packageName)
23+
}
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.App.Starting"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true"
18+
android:label="@string/app_name"
19+
android:theme="@style/Theme.PowerSyncAndroidExample">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
</application>
27+
28+
</manifest>

0 commit comments

Comments
 (0)