How to use Realm Gradle Plugin with Version Catalogs?

Hello. As part of an app migration, my team is moving to version catalogs using toml. But, there is an issue because I cannot find info about the correct id for the Realm Gradle Plugin. Currently I have this in build.gradle:

buildscript {
    dependencies {
        classpath 'io.realm:realm-gradle-plugin:10.15.1'
    }
}

And then, I have tried this in the libs.versions.toml file:

[versions]
realm-gradle-plugin = "10.15.1"

[plugins]
realm-gradle-plugin = { id = "io.realm:realm-gradle-plugin", version.ref = "realm-gradle-plugin" }

But this fails when trying to sync the project. I also have tried with variations like io.realm.realm-gradle-plugin and io.realm.realm.gradle.plugin, but these didn’t work either.

I am using it like this →

[versions]
realmGradlePlugin = "10.17.0"

[libraries]
realm-gradle-plugin = { module = "io.realm:realm-gradle-plugin", version.ref = "realmGradlePlugin" }

[plugins]
org-jetbrains-kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }

in

project level build.gradle:

plugins {
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.jetbrainsKotlinAndroid) apply false
    alias(libs.plugins.org.jetbrains.kotlin.kapt) apply false
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath(libs.realm.gradle.plugin)
    }
}

module level build.gradle:

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsKotlinAndroid)
    alias(libs.plugins.org.jetbrains.kotlin.kapt)
    id("realm-android")
}
2 Likes

Hello Yunus,
I have followed your way of using the Realm Plugin, but in my project, i cannot extend my class Adapter class with RealmRecyclerViewAdapter<>, it didn’t show anything related to it in the suggestion too.

Regards,
Shen

Did you try to implement realm adapters?

I am using RealmRecyclerViewAdapter like this:

In app level build gradle’s dependencies:

//Realm
implementation(libs.realm.android.adapters)

In .toml file:

[versions]
realmAndroidAdapters = "3.1.0"

[libraries]
realm-android-adapters = { module = "com.github.realm:realm-android-adapters", version.ref = "realmAndroidAdapters" }

I too have similar issue