Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realm can not find RealmObject extended models which are present in my custom .jar #693

Closed
ghost opened this issue Dec 22, 2014 · 9 comments
Labels

Comments

@ghost
Copy link

ghost commented Dec 22, 2014

Hi,

I am creating a jar which contains Realm Models for storing data. Then user will add my jar and realm.jar seperatly in his project. so, in this scenario inside ".apt_generated" annotation folder the required proxy classes for realm are not getting generated as a result there is no entry in ValidationList.java class.

Below is the exception -
java.lang.IllegalStateException: Objects cannot be changed outside a transaction; see beginTransaction() for details.
W/System.err( 4036): at io.realm.internal.Group.throwImmutable(Group.java:318)
W/System.err( 4036): at io.realm.internal.Group.getTable(Group.java:213)
W/System.err( 4036): at io.realm.Realm.getTable(Realm.java:233)
W/System.err( 4036): at io.realm.RealmQuery.getTable(RealmQuery.java:101)
W/System.err( 4036): at io.realm.RealmQuery.(RealmQuery.java:58)
W/System.err( 4036): at io.realm.Realm.where(Realm.java:756)

@bmunkholm
Copy link
Contributor

Are you sure the title of this issues is the problem? Not that you forgot to start a transaction before modifying your object? How do you get to that conclusion?

@ghost
Copy link
Author

ghost commented Dec 23, 2014

Hi bmunkholm,

Sorry to confuse with the transaction error. I was getting this for other reason.

I still see one issue in using Realm with jar having model files that extends RealmObject.

I included the jar in the project and also have the Realm jar in the same project.

The anotation process creates the proxy class for all the extended Realm object that are defined in the application but it fails to scan jar(compiled class files) and generate the anotation object.

As far as my understanding, anotation works on the source(.java) files and not on the compiled(.class) files.

Let me know if I am misunderstanding something here?

Thanks for all the help and support.

Please Find Project link
(https://www.dropbox.com/s/9ozve1amifz171d/MyJarProject.zip?dl=0)

@kneth
Copy link
Contributor

kneth commented Dec 25, 2014

The model classes are processed and proxy classes are created. If your model class is FooBar, the class FooBarProxy is created in a separate file. These are compiled, and you need to include them in the jar file. For example, you have to include FooBarProxy.class as well as FooBar.class.

@kneth kneth added the T-Help label Dec 25, 2014
@ghost
Copy link
Author

ghost commented Dec 29, 2014

Hi @kneth,

Thanks for reply. I followed your tips and included all proxy classes in a jar. It's really great works with realm models which are present within a jar.

But when I use jar in project where other realm models were present, then it's started giving multiple Dex error:

com.android.dex.DexException: Multiple dex files define Lio/realm/ValidationList;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)

So, After that I customized .jar and removed "io/realm/ValidationList" file then I get "Null pointer exception" inside proxy class.

proxy class function & line where i got exception -

@OverRide
public void setId(String value) {
realm.checkIfValid();
//below line.
row.setString(Realm.columnIndices.get("UserModel").get("id"), (String) value);
}

Can you please tell me where i am missing things?

Realm is very quick and simple startup comparing with sqllite in application development. I would really like to use for third party libs.

Thanks for all the help and support.

@cmelchior
Copy link
Contributor

Hi @Chinmay-Acharya
Just to follow up on this.
The ValidationList files contains the list of Model classes that Realm should know about. If you just deleted the ValidationList file from you library project, Realm in the app project doesn't know that the models in your library exists, thus the Nullpointer when you try to use them.

Instead you should copy all the strings from you library ValidationList file to your app ValidationList. It is a bit cumbersome and manually process atm, but we plan to make it a lot simpler going forward.

@bmunkholm
Copy link
Contributor

@Chinmay-Acharya Did this help you? Please close the issue if no problems.

@ghost
Copy link
Author

ghost commented Jan 28, 2015

Hi @cmelchior and @bmunkholm ,
Thanks for the reply. I followed your instructions and copy pasted all the strings in ValidationList.java class. So, jar realm model became accessible.

But in android studio, If project get build then user need to follow all the process again and again.

So currently, I am using SQL lite for library creation. I am really looking forward and curious for simpler version.

@ghost ghost closed this as completed Jan 28, 2015
@evasquezcr
Copy link

Hello @cmelchior , I've been working with Realm and Parceler, I saw that I need to use :

@parcel(implementations = { FooBarProxy.class}, value = Parcel.Serialization.BEAN, analyze = {FooBar.class})

Well, I don't know how or where my 'Proxy.class' is generated... where can I find it?

Thanks!

@cmelchior
Copy link
Contributor

It is under build/intermediates/classes but you need the APT Gradle plugin in your build file to be able to reference the classes there: https://bitbucket.org/hvisser/android-apt.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants