realm-java: Realm does not support Kotlin ByteArray type (java byte[])
Goal
use ByteArray ( kotlin’s byte[] alias) with Realm
example:
open class TestModel( @RealmField(name = "test") var test: ByteArray? = ByteArray(0)): RealmObject()
Expected Results
compiles fine
Actual Results
error: Field "test" of type "(@org.jetbrains.annotations.Nullable :: byte)[]" is not supported.
Code Sample
kotlin version which does not compile:
open class TestModel(
@RealmField(name = "test")
var test: ByteArray? = ByteArray(0)): RealmObject()`
java version which compile fine:
public class TestModel extends RealmObject {
@RealmField(name = "test")
public byte[] test;
}
Version of Realm and tooling
Realm version(s): ?=5.5.0
Realm sync feature enabled: no
Android Studio version: 3.2
Which Android version and device: emulator 8.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (1 by maintainers)
I had the same error after updating some library versions. These two caused it:
I tried with realm 4.1.1 and 5.8.0, but it didn’t help. conductor and timber were the problems for me. I assume this behavior is a bug in annotation processing from some other library or plugin, so your solution might be different than mine, but I suggest you check whether you updated any libraries.
I’ve got this after adding
Timber 4.7.1
to the project This is the log:I’ve done little research and:
Constants.JAVA_TO_REALM_TYPES
has “byte[]” (string) as Type. Then it’s used to check supported field types inRealmProxyClassGenerator.emitPersistedFieldAccessors
wherefield.asType().toString()
=fieldTypeCanonicalName
should bebyte[]
but it is(@org.jetbrains.annotations.NotNull :: byte)[]
I solved my problem by creating a small Java class that contained the byte array. It avoids the annotation. Thanks!