Realm-java: ClassNotFoundException: RealmModuleMediator

Created on 12 Nov 2016  路  13Comments  路  Source: realm/realm-java

Bugs: To help you as fast as possible with an issue or bug please describe your issue and the steps you have taken to reproduce it in as many details as possible.

Goal

Desired functionality:
Have four separate modules in my app: app, data, domain and presentation, where the layers are:

Domain --> Data --> Presentation --> App.

The build.gradle of Data has the realm-android plugin installed, and a RealmModule annotated with @RealmModule(library = true, allClasses = true).

Presentation takes RealmObjects from Data and converts them into simple POJOs for the App.

What do you want to achieve?

Expected Results:

Realm recognizes the RealmObject classes specified in my RealmModule.

Actual Results

An exception occurs during runtime (not compile time), saying that Realm could not find my RealmModule class.

Steps & Code to Reproduce

Describe your current debugging efforts.

Impeded

E.g. full stack trace with exception

FATAL EXCEPTION: main
Process: , PID: 24359
java.lang.RuntimeException: Unable to start activity ComponentInfo{/.LoginActivity}: io.realm.exceptions.RealmException: Could not find io.realm.ModuleMediator
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: io.realm.exceptions.RealmException: Could not find io.realm.Module
at io.realm.RealmConfiguration.getModuleMediator(RealmConfiguration.java:300)
at io.realm.RealmConfiguration.createSchemaMediator(RealmConfiguration.java:274)
at io.realm.RealmConfiguration$Builder.build(RealmConfiguration.java:665)
at org.unos.ett.api.repository.base.RealmLifecycle.(RealmLifecycle.java:20)
at org.unos.ett.app.dagger.module.DatabaseModule.lifecycle(DatabaseModule.java:54)
at org.unos.ett.app.dagger.module.DatabaseModule_LifecycleFactory.get(DatabaseModule_LifecycleFactory.java:19)
at org.unos.ett.app.dagger.module.DatabaseModule_LifecycleFactory.get(DatabaseModule_LifecycleFactory.java:8)
at org.unos.ett.app.dagger.component.DaggerAppComponent$DatabaseComponentImpl.lifecycle(DaggerAppComponent.java:129)
at org.unos.ett.app.dagger.component.DaggerLoginComponent$3.get(DaggerLoginComponent.java:71)
at org.unos.ett.app.dagger.component.DaggerLoginComponent$3.get(DaggerLoginComponent.java:65)
at org.unos.ett.app.dagger.module.LoginModule_LoginPresenterFactory.get(LoginModule_LoginPresenterFactory.java:40)
at org.unos.ett.app.dagger.module.LoginModule_LoginPresenterFactory.get(LoginModule_LoginPresenterFactory.java:12)
at org.unos.ett.app.ui.fragment.LoginFragment_MembersInjector.injectMembers(LoginFragment_MembersInjector.java:25)
at org.unos.ett.app.ui.fragment.LoginFragment_MembersInjector.injectMembers(LoginFragment_MembersInjector.java:8)
at org.unos.ett.app.dagger.component.DaggerLoginComponent.inject(DaggerLoginComponent.java:89)
at org.unos.ett.app.ui.fragment.LoginFragment.onAttach(LoginFragment.java:71)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:937)
at android.app.BackStackRecord.setLastIn(BackStackRecord.java:860)
at android.app.BackStackRecord.calculateFragments(BackStackRecord.java:883)
at android.app.BackStackRecord.run(BackStackRecord.java:728)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentController.execPendingActions(FragmentController.java:371)
at android.app.Activity.performStart(Activity.java:6695)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)聽
at android.app.ActivityThread.-wrap12(ActivityThread.java)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)聽
at android.os.Handler.dispatchMessage(Handler.java:102)聽
at android.os.Looper.loop(Looper.java:154)聽
at android.app.ActivityThread.main(ActivityThread.java:6119)聽
at java.lang.reflect.Method.invoke(Native Method)聽
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)聽
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)聽
Caused by: java.lang.ClassNotFoundException: io.realm.Module
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at java.lang.Class.forName(Class.java:326)
at io.realm.RealmConfiguration.getModuleMediator(RealmConfiguration.java:295)
at io.realm.RealmConfiguration.createSchemaMediator(RealmConfiguration.java:274)聽
at io.realm.RealmConfiguration$Builder.build(RealmConfiguration.java:665)聽
at org.unos.ett.api.repository.base.RealmLifecycle.(RealmLifecycle.java:20)聽
at org.unos.ett.app.dagger.module.DatabaseModule.lifecycle(DatabaseModule.java:54)聽
at org.unos.ett.app.dagger.module.DatabaseModule_LifecycleFactory.get(DatabaseModule_LifecycleFactory.java:19)聽
at org.unos.ett.app.dagger.module.DatabaseModule_LifecycleFactory.get(DatabaseModule_LifecycleFactory.java:8)聽
at org.unos.ett.app.dagger.component.DaggerAppComponent$DatabaseComponentImpl.lifecycle(DaggerAppComponent.java:129)聽
at org.unos.ett.app.dagger.component.DaggerLoginComponent$3.get(DaggerLoginComponent.java:71)聽
at org.unos.ett.app.dagger.component.DaggerLoginComponent$3.get(DaggerLoginComponent.java:65)聽
at org.unos.ett.app.dagger.module.LoginModule_LoginPresenterFactory.get(LoginModule_LoginPresenterFactory.java:40)聽
at org.unos.ett.app.dagger.module.LoginModule_LoginPresenterFactory.get(LoginModule_LoginPresenterFactory.java:12)聽
at org.unos.ett.app.ui.fragment.LoginFragment_MembersInjector.injectMembers(LoginFragment_MembersInjector.java:25)聽
at org.unos.ett.app.ui.fragment.LoginFragment_MembersInjector.injectMembers(LoginFragment_MembersInjector.java:8)聽
at org.unos.ett.app.dagger.component.DaggerLoginComponent.inject(DaggerLoginComponent.java:89)聽
at org.unos.ett.app.ui.fragment.LoginFragment.onAttach(LoginFragment.java:71)聽
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:937)聽
at android.app.BackStackRecord.setLastIn(BackStackRecord.java:860)聽
at android.app.BackStackRecord.calculateFragments(BackStackRecord.java:883)聽
at android.app.BackStackRecord.run(BackStackRecord.java:728)聽
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)聽
at android.app.FragmentController.execPendingActions(FragmentController.java:371)聽
at android.app.Activity.performStart(Activity.java:6695)聽
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2628)聽
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)聽
at android.app.ActivityThread.-wrap12(ActivityThread.java)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)聽
at android.os.Handler.dispatchMessage(Handler.java:102)聽
at android.os.Looper.loop(Looper.java:154)聽
at android.app.ActivityThread.main(ActivityThread.java:6119)聽
at java.lang.reflect.Method.invoke(Native Method)聽
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)聽
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)聽
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.ModuleMediator" on path: DexPathList[[zip file "/data/app/...1/base.apk"],nativeLibraryDirectories=[/data/app/...-1/lib/x86, /data/app/...-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]

Version of Realm and tooling

Realm version(s): 2.2.0

Realm sync feature enabled: no

Android Studio version: 2.0 RC1

Which Android version and device: 25, Nexus 7

T-Help

Most helpful comment

That is strange, it should work in this order:

apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

I wonder if it works differently for library projects...?

All 13 comments

Same problem here, using Realm 2.2.0 and Android Studio 2.3 canary. Was working fine on 2.1.1, performing a full clean and rebuild does not help.

Above poster provides solution for now, downgrading to 2.1.1 works.

I believe this might be related to the fix with support for annotationProcessor in https://github.com/realm/realm-java/pull/3754 and also to https://github.com/realm/realm-java/issues/3783

Do you use android-apt plugin?

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

apply plugin: 'com.neenbedankt.android-apt'

If you don't, and you don't use Kotlin, then can you try?

I vote this be re-opened. I added the annotation processor in my data/ module, and still got the same error.

just like @akm0012 I also need apt for ButterKnife. Removing it and re-adding it after a full clean build however did not solve the issue. For now downgrading to 2.1.1 seems to be the only solution for me.

@unosmiles / @AlexLardschneider Can you post your gradle files?

Global build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: 'gradle/config.gradle'

buildscript {
repositories {
jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    classpath 'io.realm:realm-gradle-plugin:2.1.1'
}

}

allprojects {
repositories {
mavenCentral()
jcenter()
}
}

data module build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'realm-android'

def config = rootProject.extensions.getByName("ext")

android {
compileSdkVersion config.getAt("compileSdkVersion")
buildToolsVersion config.getAt("buildToolsVersion")

defaultConfig {
    minSdkVersion config.getAt("minSdkVersion")
    targetSdkVersion config.getAt("targetSdkVersion")
}

}

dependencies {
compile project(':domain')

apt group: 'dk.ilios', name: 'realmfieldnameshelper',  version: '1.1.0'

compile group: 'com.android.support', name: 'support-annotations', version: '25.0.0'

}

apply plugin: 'com.neenbedankt.android-apt' seems to be missing

Was the issue solved when the above plugin was added?

Sorry for the late response, and thanks for staying on top of this. No, unfortunately that did not. The only solution that I found was downgrading the Realm version.

That is strange, it should work in this order:

apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'

I wonder if it works differently for library projects...?

When I get a chance, I will test that.

I close the issue. @unosmiles If it doesn't work, please either reopen or create a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wyvern610 picture wyvern610  路  3Comments

gpulido picture gpulido  路  3Comments

aschrijver picture aschrijver  路  3Comments

mithrann picture mithrann  路  3Comments

AlbertVilaCalvo picture AlbertVilaCalvo  路  3Comments