realmfieldnameshelper icon indicating copy to clipboard operation
realmfieldnameshelper copied to clipboard

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

Open ursusursus opened this issue 7 years ago • 6 comments

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 avatar Nov 29 '17 05:11 ursusursus

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

ursusursus avatar Nov 29 '17 05:11 ursusursus

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)

Zhuinden avatar Nov 29 '17 09:11 Zhuinden

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

ursusursus avatar Nov 29 '17 15:11 ursusursus

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

Zhuinden avatar Nov 29 '17 19:11 Zhuinden

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

ursusursus avatar Nov 29 '17 19:11 ursusursus

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

ursusursus avatar Nov 30 '17 18:11 ursusursus