Description
How frequently does the bug occur?
Always
Description
We've recently decided to migrate from java-sdk to to the kotlin-sdk and when the app is first started right after the migration, the encrypted realm file cannot be opened with the same key that has been used to encrypt the realm prior to the migration to the kotlin-sdk. The error we're getting is as follows:
[RLM_ERR_INVALID_DATABASE]: Failed to open Realm file at path '/data/user/0/com.example.app/files/default.realm': Realm file decryption failed (Decryption failed: 'unable to decrypt after 0 seconds (retry_count=4, from=i != bytes_read, size=4096)')
Here are details about the SDK versions:
// Java-sdk version prior to migration
implementation("io.realm:realm-gradle-plugin:10.11.1")
// Kotlin-sdk version after the migration
implementation ("io.realm.kotlin:library-base:1.11.0")
We've verified that the key used for the realm config is the same before and after the migration so there should be no issue with the key itself. In addition, we did tests with unencrypted realm and in this case we don't have issues with the migration.
In addition, we tried to open the realm file using Realm Studio by providing the encryption key. We get warning that the realm file is in an outdated format which I'm not sure is related to the issue but after choosing the Backup and upgrade
option, we are able to decrypt the realm database and see the content - everything is in there.

Here is the code for generating the realm config:
private fun initRealmConfig(): RealmConfiguration? {
// Increment whenever you made changes to the Realm* database models
val schemaVersion: Long = 2
// Get encryption key
val realmKey = DBHelper.loadEncryptionKey(App.applicationContext())
realmKey?.let {
val realmConfig = RealmConfiguration.Builder(getSchemaClasses())
.schemaVersion(schemaVersion)
.migration(DBMigrationHelper.migrate())
.encryptionKey(it)
.build()
// Once we've used the key to generate a config, erase it in memory manually
Arrays.fill(realmKey, 0.toByte())
return realmConfig
}
return null
}
Stacktrace & log output
[RLM_ERR_INVALID_DATABASE]: Failed to open Realm file at path '/data/user/0/com.example.app/files/default.realm': Realm file decryption failed (Decryption failed: 'unable to decrypt after 0 seconds (retry_count=4, from=i != bytes_read, size=4096)')
Can you reproduce the bug?
Always
Reproduction Steps
- Run app version with java-sdk
- Migrate to kotlin-sdk
- Update the installed app version in step 1 with the migrated version
Problem
- Realm decryption fails
Version
1.11.0
What Atlas App Services are you using?
Local Database only
Are you using encryption?
Yes
Platform OS and version(s)
Android
Build environment
Android Studio version: Hedgehog | 2023.1.1 Patch 2
Android Build Tools version: com.android.tools.build:gradle:7.2.2
Gradle version: gradle-7.4-bin