Model cannot be cast to ModelRealmProxyInterface while using realm jars built from source in Android Project
73sravanthi opened this issue · 6 comments
How frequently does the bug occur?
Always
Description
I am using Realm jars which are built from source code. I have added realm-library aar file, realm-annotations-10.18.0.jar, realm-transformer-10.18.0.jar, realm-gradle-plugin into libs folder of Android project and tried to build. Able to launch the application however getting
UserModel cannot be cast to io.realm.com_example_mobile_test_auth_model_UserModelRealmProxyInterface
whenever any db operation is performed
Stacktrace & log output
2024-03-07 15:45:21.304 5922-5922 ExampleException com.example D null : null
2024-03-07 15:45:21.305 5922-5922 ExampleException com.example D
UserModel cannot be cast to io.realm.com_example_mobile_test_auth_model_UserModelRealmProxyInterface
Can you reproduce the bug?
Always
Reproduction Steps
Build the realm code base from source
Version
10.18.0
What Atlas App Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
Mac OS 14.3
Build environment
Android Studio version: Android Studio Hedgehog | 2023.1.1 Patch 2
Android Build Tools version: 33.0.1
Gradle version: 8
➤ PM Bot commented:
Jira ticket: RJAVA-1251
Any help on this. Stuck with the above error and unable to proceed
Looks like you are not transforming the realm model classes. If you don't apply our plugin you will have to register the transformer yourself.
Adding the realm-transformer jar file to libs doesn't help here?
Is there any way to apply the plugin using jar file.
Earlier I used android.registerTransform(new RealmTransformer(rootProject)) to register but in Gradle 8 android.registerTransform is deprecated.
Any help on this
I have tried using
import io.realm.transformer.RealmTransformerKt
RealmTransformerKt.registerRealmTransformerTask(rootProject)
to register the RealmTransformer in the build.gradle file, however getting below error while trying to build it
Caused by: org.gradle.api.UnknownDomainObjectException: Extension of type 'AndroidComponentsExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, KtlintExtension]
at org.gradle.internal.extensibility.ExtensionsStorage.getHolderByType(ExtensionsStorage.java:88)
at org.gradle.internal.extensibility.ExtensionsStorage.getByType(ExtensionsStorage.java:74)
at org.gradle.internal.extensibility.DefaultConvention.getByType(DefaultConvention.java:160)
at org.gradle.internal.extensibility.DefaultConvention.getByType(DefaultConvention.java:155)
at io.realm.transformer.RealmTransformerKt.registerRealmTransformerTask(RealmTransformer.kt:88)
at io.realm.transformer.RealmTransformerKt$registerRealmTransformerTask.call(Unknown Source)
Let me know if I missed anything here