realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.47k stars 1.75k forks source link

Model cannot be cast to ModelRealmProxyInterface while using realm jars built from source in Android Project #7875

Open 73sravanthi opened 8 months ago

73sravanthi commented 8 months ago

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

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

➤ PM Bot commented:

Jira ticket: RJAVA-1251

73sravanthi commented 8 months ago

Any help on this. Stuck with the above error and unable to proceed

rorbech commented 8 months ago

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.

73sravanthi commented 8 months ago

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.

73sravanthi commented 8 months ago

Any help on this

73sravanthi commented 8 months ago

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