Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm NoClassDefFoundError: rx.Observable

Tags:

android

realm

I am experiencing an issue that is pointed out in Realm's documentation:

Jackson Databind

Jackson Databind is a library for binding JSON data to Java classes.

Jackson uses reflection to perform the data binding. This conflicts with Realm’s support for RxJava, as RxJava might not be available to the class loader. This can result in an exception that looks like this:

Copy to clipboardjava.lang.NoClassDefFoundError: rx.Observable
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
...

Here is the proposed fix:

This can be fixed by either adding RxJava to your project or create two empty dummy files that looks like the following.

Copy to clipboard// File 1
package io.reactivex;

public class Flowable {
}


// File 2
package io.reactivex;

public class Observable {
}

This issue has also been reported to the Jackson project here.

Question: Where do I create the files so they don't have my app's package name? (ex: com.myApp.myPackage)

Side note: I'm experiencing this from SimpleXml, not Jackson (maybe simplexml uses jackson?). I've seen 2 errors:

  1. Realm NoClassDefFoundError: rx.Observable Realm
  2. NoClassDefFoundError: io.reactivex.Observable
like image 698
Psest328 Avatar asked Jun 08 '26 05:06

Psest328


1 Answers

You are using Realm older than v4.0.0, so you need to create package rx, and the dummy class called Observable. But you just need to create it in src/main/java/rx.

package rx;

public class Observable {
}

For Realm 4.0.0+, you need in src/main/java/io/reactivex.

package io.reactivex;

public class Observable {
}

and

package io.reactivex;

public class Flowable {
}

and

package io.reactivex;

public enum BackpressureStrategy {
  MISSING,
  ERROR,
  BUFFER,
  DROP,
  LATEST
}
like image 131
EpicPandaForce Avatar answered Jun 10 '26 17:06

EpicPandaForce