From d67f484252e1086cd8df36f3838d59f87585813e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Wed, 3 Apr 2024 14:12:12 +0200 Subject: [PATCH] Update java compatibility example to latest Realm Java --- buildSrc/build.gradle.kts | 4 +-- buildSrc/src/main/kotlin/Config.kt | 2 +- .../app/src/main/AndroidManifest.xml | 1 + .../demo/javacompatibility/MainApplication.kt | 8 +++-- .../demo/javacompatibility/data/Repository.kt | 2 ++ .../data/java/JavaRepository.kt | 33 +++++++++++++++++-- .../data/kotlin/KotlinRepository.kt | 7 ++++ .../realm-java-compatibility/build.gradle.kts | 2 +- 8 files changed, 50 insertions(+), 9 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index ee2e79fee3..077d2bd5fe 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -30,8 +30,8 @@ gradlePlugin { } java { - sourceCompatibility = Versions.sourceCompatibilityVersion - targetCompatibility = Versions.targetCompatibilityVersion + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } repositories { diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index fa440841c2..0cf8af8dc1 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -101,7 +101,7 @@ object Versions { const val targetSdk = 33 const val compileSdkVersion = 33 const val buildToolsVersion = "33.0.0" - const val buildTools = "7.3.1" // https://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle + const val buildTools = "7.4.2" // https://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle const val ndkVersion = "23.2.8568313" const val r8 = "8.0.34" // See https://developer.android.com/build/kotlin-support } diff --git a/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml b/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml index 6e0af0f69d..dcf4535210 100644 --- a/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml +++ b/examples/realm-java-compatibility/app/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ + + subscriptions.addOrUpdate(Subscription.create("JavaEntity", realm.where(JavaEntity::class.java))) + } .name("java.realm") .allowWritesOnUiThread(true) .build() - Realm.deleteRealm(config) realm = Realm.getInstance(config) realm.executeTransaction { - realm.createObject(JavaEntity::class.java) + realm.createObject(JavaEntity::class.java, ObjectId()) val entities = realm.where(JavaEntity::class.java).findAll() Log.d(TAG, "JAVA: ${entities.size}") } @@ -60,4 +84,7 @@ class JavaRepository(appContext: Context) : Repository { override val count: Int = realm.where(JavaEntity::class.java).findAll().count() + override fun close() { + realm.close() + } } diff --git a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt index b6310f00d3..46e4488f5a 100644 --- a/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt +++ b/examples/realm-java-compatibility/app/src/main/java/io/realm/kotlin/demo/javacompatibility/data/kotlin/KotlinRepository.kt @@ -22,6 +22,8 @@ import io.realm.kotlin.RealmConfiguration import io.realm.kotlin.demo.javacompatibility.TAG import io.realm.kotlin.demo.javacompatibility.data.Repository import io.realm.kotlin.ext.query +import io.realm.kotlin.log.LogLevel +import io.realm.kotlin.log.RealmLog import io.realm.kotlin.types.RealmObject import io.realm.kotlin.types.annotations.PrimaryKey @@ -36,7 +38,9 @@ class KotlinRepository: Repository { val realm: Realm init { + RealmLog.level = LogLevel.ALL val config = RealmConfiguration.Builder(setOf(KotlinEntity::class)) + .name("kotlin.realm") .build() Realm.deleteRealm(config) @@ -47,4 +51,7 @@ class KotlinRepository: Repository { } override val count = realm.query().find().size + override fun close() { + realm.close() + } } diff --git a/examples/realm-java-compatibility/build.gradle.kts b/examples/realm-java-compatibility/build.gradle.kts index 4446b68891..5acc554c10 100644 --- a/examples/realm-java-compatibility/build.gradle.kts +++ b/examples/realm-java-compatibility/build.gradle.kts @@ -29,7 +29,7 @@ buildscript { mavenCentral() } dependencies { - classpath ("io.realm:realm-gradle-plugin:10.11.0") + classpath ("io.realm:realm-gradle-plugin:10.18.0") classpath ("io.realm.kotlin:gradle-plugin:${Realm.version}") } }