cmelchior / realmfieldnameshelper

Realm extension library used to create more type-safe queries.
Apache License 2.0
173 stars 21 forks source link

ClassNotFoundException when referencing model from library module in model from app module #32

Open ursusursus opened 6 years ago

ursusursus commented 6 years ago

Hi, I am trying to get realm working inside library and app module. I get it working using the example you provide in the docs, separating libraryModule and Realm.getDefaultModule etc. Works.

However if I reference a library model inside a app model like

MyAppItem extends RealmObject {
    MyLibraryItem item;
}

It will fail at compile time with ClassNotFoundException for MyLibraryItem

AS 3.0 gradle plugin 3.0.0 realm plugin 4.2.0 dk.ilios:realmfieldnameshelper:1.1.1

Caused by: java.lang.ClassNotFoundException: io.realm.examples.librarymodules.model.Cat
    at dk.ilios.realmfieldnames.RealmFieldNamesProcessor.processLibraryClass(RealmFieldNamesProcessor.kt:127)
    at dk.ilios.realmfieldnames.RealmFieldNamesProcessor.access$processLibraryClass(RealmFieldNamesProcessor.kt:24)
    at dk.ilios.realmfieldnames.RealmFieldNamesProcessor$process$$inlined$forEach$lambda$1.accept(RealmFieldNamesProcessor.kt:85)
    at dk.ilios.realmfieldnames.RealmFieldNamesProcessor$process$$inlined$forEach$lambda$1.accept(RealmFieldNamesProcessor.kt:24)
    at dk.ilios.realmfieldnames.RealmFieldNamesProcessor.process(RealmFieldNamesProcessor.kt:81)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
    at com.sun.tools.javac.main.Main.compile(Main.java:523)
    ... 56 more
ursusursus commented 6 years ago

Very blocking issue for my project, since Its a modularization of a existing project I cant just drop it

Zhuinden commented 6 years ago

The library class should be on the classpath according to the comment

So you might want to use api instead of implementation scope for your library dependency (but compile should also work)

ursusursus commented 6 years ago

I am no that familiar with the new gradle apis. However with implementation I can use MyLibraryItem inside :app, say new MyLibraryItem() in MainActivity, compilation fails only if its a realm child field

Zhuinden commented 6 years ago

@ursusursus yes, but you need to change it to api instead of implementation.

ursusursus commented 6 years ago

@Zhuinden Yea sorry I forgot to add that to comment, Ive tried the api also and same error

ursusursus commented 6 years ago

Its reproducable on moduleExample from realm examples, just add

public class Cow extends RealmObject {

    private String name;
    private Dog dog;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

and annotationProcessor "dk.ilios:realmfieldnameshelper:1.1.1". Regardless of api project(':moduleExample:library') or implementation