Psest328
Psest328

Reputation: 6675

Realm NoClassDefFoundError: rx.Observable

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

Upvotes: 3

Views: 2941

Answers (1)

EpicPandaForce
EpicPandaForce

Reputation: 81568

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
}

Upvotes: 14

Related Questions