The official Android client for Convex.
Convex is the backend application platform with everything you need to build your product.
This library lets you create Convex applications that run on Android. It builds on the Convex Rust client and offers a convenient Android API for executing queries, actions and mutations.
If you haven't started a Convex application yet, head over to the Convex Android quickstart to get the basics down. It will get you up and running with a Convex dev deployment and a basic Android application that communicates with it using this library.
Also join us on Discord to get your questions answered or share what you're doing with Convex.
Add the following to your app's build.gradle.kts
file:
plugins {
// ... existing plugins
kotlin("plugin.serialization") version "1.9.0"
}
dependencies {
// ... existing dependencies
implementation("dev.convex:android-convexmobile:0.4.0@aar") {
isTransitive = true
}
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
}
Also ensure that your AndroidManifest.xml
file has the INTERNET
permission declared.
<uses-permission android:name="android.permission.INTERNET"/>
@Serializable
data class YourData(val foo: String, val bar: @ConvexNum Int)
val client = ConvexClient("your convex deployment URL")
// Use the ConvexClient methods in a CoroutineScope.
// results will contain a Flow that will automatically update when the query data changes
val results: Flow<Result<YourData>> = client.subscribe("your:query", mapOf("someArg" to "someVal"))
client.mutation("your:mutation", mapOf("anotherArg" to "anotherVal", "aNumber" to 42))
Follow along here if you're interested in hacking on the Android client.
You'll need a working Rust installation to build this library.
-
Ensure you have build tools available on your OS (XCode on Mac,
build-essential
on Linux) -
Install Android Studio
-
Use the SDK Manager to install NDK version 27.0.11902837
- Open android studio. Press shift-shift and search sdk manager
- In the SDK tools tab, go to "NDK".
- Check the "show package details" box to get more options
- Select NDK version 27.0.11902837
- On Mac it will be installed somewhere like
/Users/$USER/Library/Android/sdk/ndk/
-
Add the following to
~/.cargo/config.toml
(use your NDK path)[target.aarch64-linux-android] linker = "${your NDK x.y.z path}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang" [target.armv7-linux-androideabi] linker = "${your NDK x.y.z path}/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi35-clang"
-
Run
rustup target add armv7-linux-androideabi aarch64-linux-android
-
Open
convex-mobile/android
in Android Studio (wait for it to sync) -
Double press Ctrl and type
./gradlew build
-
Set up GPG key/passphrase https://central.sonatype.org/publish/requirements/gpg/
-
Make sure to follow through the instructions, including adding to ~/.gradle/gradle.properties and
gpg --keyserver pgp.mit.edu --send-keys {key}
-
Set credentials in gradle.properties https://central.sonatype.org/publish/publish-gradle/#credentials
-
You can generate a local Maven installable package by running
./gradlew publishToMavenLocal