realm / realm-kotlin

Kotlin Multiplatform and Android SDK for the Realm Mobile Database: Build Better Apps Faster.
Apache License 2.0
880 stars 52 forks source link

Unable to use initialRealmFile with compose multiplatform resources #1719

Closed H4kt closed 2 months ago

H4kt commented 2 months ago

How frequently does the bug occur?

Always

Description

Compose multiplatform 1.6.0 introduced native support for resources Placing a realm file into composeResources/files and then using it in a real configuration via .initialRealmFile("...") results in an error that asset file is not found

Stacktrace & log output

Caused by: java.lang.IllegalArgumentException: Asset file not found: 'ral_colors.realm'
    at io.realm.kotlin.internal.util.Exceptions.assetFileNotFound(Exceptions.kt:26)
    at io.realm.kotlin.internal.platform.SystemUtilsAndroidKt.assetFileAsStream(SystemUtilsAndroid.kt:36)
    at io.realm.kotlin.internal.platform.SystemUtilsKt.copyAssetFile(SystemUtils.kt:66)
    at io.realm.kotlin.internal.RealmImpl$1.invokeSuspend(RealmImpl.kt:128)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
    at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(CoroutineUtilsSharedJvm.kt:22)
    at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(CoroutineUtilsSharedJvm.kt:21)
    at io.realm.kotlin.internal.RealmImpl.<init>(RealmImpl.kt:115)
    at io.realm.kotlin.internal.RealmImpl.<init>(Unknown Source:0)
    at io.realm.kotlin.internal.RealmImpl$Companion.create$io_realm_kotlin_library(RealmImpl.kt:318)
    at io.realm.kotlin.Realm$Companion.open(Realm.kt:83)
    at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:50)
    ... 149 more
Caused by: java.io.FileNotFoundException: ral_colors.realm
    at android.content.res.AssetManager.nativeOpenAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:904)
    at android.content.res.AssetManager.open(AssetManager.java:881)
    at io.realm.kotlin.internal.RealmInitializer$Companion.asset(RealmInitializer.kt:36)
    at io.realm.kotlin.internal.platform.SystemUtilsAndroidKt.assetFileAsStream(SystemUtilsAndroid.kt:34)
    ... 167 more

Can you reproduce the bug?

Always

Reproduction Steps

  1. Setup a compose multiplatform project with compose version 1.6.0 or higher
  2. Place a realm file into composeResources/files
  3. Attempt to use that file as a inital realm file via .initialRealmFile("...")

Version

1.14.1

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android

Build environment

Android Studio version: 2023.2.1 Android Build Tools version: agp 8.2.2 Gradle version: 8.4

sync-by-unito[bot] commented 2 months ago

➤ PM Bot commented:

Jira ticket: RKOTLIN-1066

rorbech commented 2 months ago

This is not an issue with realm, but merely an issue with Compose not putting the resources in platform standard locations as expected by the SDK. It isn't feasible for us to depend on Compose just for the sake of this. We can maybe hope that this will be extracted into a bare non-Compose KMP feature. Alternative you could try to file an issue for Compose to place the resource files where the normal platform frameworks are able to find them.