Realm-java: Can't use realm without RxJava2

Created on 3 Apr 2018  ·  14Comments  ·  Source: realm/realm-java

Most helpful comment

Add android.enableD8.desugaring=true in gradle.properties.

All 14 comments

I'm not sure what your question is?
But RxJava2 support is optional, so you don't have to include RxJava2 as a dependency if you don't want to.

@cmelchior When i'm trying to compile project with realm 5.0.0 and without RxJava2, i'm receiving build exception
screen shot 2018-04-03 at 16 07 58

@ivanosh Is this happening during compile time and not when starting the app? In that case I would be interested in seeing your gradle setup

Hello. It is happening during compile time. Here is my setup:
https://www.pastiebin.com/5ac4a2f63fe63

Thanks. There isn't anything in that build file that looks overly suspicious. So this is really odd. I cannot see what version of the build tools you are using? I am assuming 3.1.0 ?

One thing does stand a little out though. Have you tried setting preDexLibraries = false instead?

hey guy you shoud import rxjava2 io.reactivex.rxjava2:rxjava:x.x.x
because Flowable can not find in rxjava(rxjava1)

RxJava1 is not supported out of the box since 4.0.0.

@cmelchior yes, 3.1.0. With preDexLibraries = false the same issue.
The problem is that users can not use latest Realm without RxJava 2 because it is contains RxJava2 imports in package i listed in my first message.

I think it will be better to move RxJava helpers from main package to separated one to make Realm dependency-free from 3rd party

This has not been a problem before, we have in fact code compiling right now that doesn't include RxJava2, e.g. https://github.com/realm/realm-java/tree/master/examples/introExample.

So I'm not sure why your setup doesn't compile, but something must be different from a "standard setup". If you create a small standalone project that still doesn't compile, I'll be happy to take a look.

minifyEnabled true in debug config. Maybe unused rx package is shrank by ProGuard?

That shouldn't matter. Those packages don't need to be there at all. We compile the library with "compileOnly 'io.reactivex.rxjava2:rxjava:2.1.5'" which ensures that it compiles but we include the RxJava files, meaning they need to be provided at runtime if you want to use the API's.

The reason the workaround posted by @Zhuinden is needed is that some libraries introspect the Realm model classes at runtime which will force the ClassLoader to load RxJava (and crashing).
But for some reason, your build system do this at compile time. There is mentioning of desugaring in your stack trace, so perhaps this is doing it (but that would be a regression from Google), but I do not see anywhere in your build.gradle where you explicitly enable desugaring. Which was why I asked what version of the build tools you are using, because I think it has been enabled by default in some of the latest beta releases.

Add android.enableD8.desugaring=true in gradle.properties.

@VenomVendor thank you!

Was this page helpful?
0 / 5 - 0 ratings