Kotlin: Installing

Add one or more modules to your project

Add dependency to your build file using the BOM.

The available modules are:

Check out the different READMEs for information about supported Kotlin targets.

Note that the minimum Android SDK version is 26. For lower versions, you need to enable core library desugaring.

implementation(platform("io.github.jan-tennert.supabase:bom:VERSION"))
implementation("io.github.jan-tennert.supabase:postgrest-kt")
implementation("io.github.jan-tennert.supabase:auth-kt")
implementation("io.github.jan-tennert.supabase:realtime-kt")
implementation platform("io.github.jan-tennert.supabase:bom:VERSION")
implementation 'io.github.jan-tennert.supabase:postgrest-kt'
implementation 'io.github.jan-tennert.supabase:auth-kt'
implementation 'io.github.jan-tennert.supabase:realtime-kt'
<dependency>
    <groupId>io.github.jan-tennert.supabase</groupId>
    <artifactId>bom</artifactId>
    <version>VERSION</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>
<dependency>
    <groupId>io.github.jan-tennert.supabase</groupId>
    <artifactId>postgrest-kt</artifactId>
</dependency>
<dependency>
    <groupId>io.github.jan-tennert.supabase</groupId>
    <artifactId>auth-kt</artifactId>
</dependency>
<dependency>
    <groupId>io.github.jan-tennert.supabase</groupId>
    <artifactId>realtime-kt</artifactId>
</dependency>

Add Ktor Client Engine to each of your Kotlin targets (required)

You can find a list of engines here

implementation("io.ktor:ktor-client-[engine]:KTOR_VERSION")
implementation 'io.ktor:ktor-client-[engine]:KTOR_VERSION'
<dependency>
    <groupId>io.ktor</groupId>
    <artifactId>ktor-client-[engine]</artifactId>
    <version>KTOR_VERSION</version>
</dependency>

Multiplatform example:

commonMain {
    dependencies {
        //Supabase modules
    }
}
jvmMain {
    dependencies {
        implementation("io.ktor:ktor-client-cio:KTOR_VERSION")
    }
}
androidMain {
    dependsOn(jvmMain.get())
}
jsMain {
    dependencies {
        implementation("io.ktor:ktor-client-js:KTOR_VERSION")
    }
}
iosMain {
    dependencies {
        implementation("io.ktor:ktor-client-darwin:KTOR_VERSION")
    }
}

Serialization

supabase-kt provides several different ways to encode and decode your custom objects. By default, KotlinX Serialization is used.

Use KotlinX Serialization.

plugins {
    kotlin("plugin.serialization") version "KOTLIN_VERSION"
}
plugins {
    id 'org.jetbrains.kotlin.plugin.serialization' version 'KOTLIN_VERSION'
}
<build>
    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <compilerPlugins>
                    <plugin>kotlinx-serialization</plugin>
                </compilerPlugins>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-serialization</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>
val supabase = createSupabaseClient(supabaseUrl, supabaseKey) {
    //Already the default serializer, but you can provide a custom Json instance (optional):
    defaultSerializer = KotlinXSerializer(Json {
        //apply your custom config
    })
}

Use Moshi.

implementation("io.github.jan-tennert.supabase:serializer-moshi:VERSION")
implementation 'io.github.jan-tennert.supabase:serializer-moshi:VERSION'
<dependency>
    <groupId>io.github.jan-tennert.supabase</groupId>
    <artifactId>serializer-moshi</artifactId>
    <version>VERSION</version>
</dependency>
val supabase = createSupabaseClient(supabaseUrl, supabaseKey) {
    defaultSerializer = MoshiSerializer()
}

Use Jackson.

implementation("io.github.jan-tennert.supabase:serializer-jackson:VERSION")
implementation 'io.github.jan-tennert.supabase:serializer-jackson:VERSION'
<dependency>
    <groupId>io.github.jan-tennert.supabase</groupId>
    <artifactId>serializer-jackson</artifactId>
    <version>VERSION</version>
</dependency>
val supabase = createSupabaseClient(supabaseUrl, supabaseKey) {
    defaultSerializer = JacksonSerializer()
}

Use custom serializer.

class CustomSerializer: SupabaseSerializer {

    override fun <T : Any> encode(type: KType, value: T): String {
        //encode value to string
    }

    override fun <T : Any> decode(type: KType, value: String): T {
        //decode value
    }

}
val supabase = createSupabaseClient(supabaseUrl, supabaseKey) {
    defaultSerializer = CustomSerializer()
}