Rxjava: java.lang.NoClassDefFoundError: io.reactivex.Flowable

Created on 11 May 2017  路  4Comments  路  Source: ReactiveX/RxJava

I use compile 'io.reactivex.rxjava2:rxjava:2.1.0' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' in my app.gradle , my app run is ok.

but for the project-request, i should use these jar from my project lib, so i download it from maven, and put it into my-project /lib , and rewrite app.gradle compile files('lib/rxjava-2.1.0.jar') compile(name: 'rxandroid-2.0.1', ext: 'aar') ,
my code

Observable.create(new ObservableOnSubscribe<String>() {

           @Override
           public void subscribe(@NonNull ObservableEmitter<String> observableEmitter) throws Exception {
               Log.i(TAG,"subcribe method");
               ..........
               observableEmitter.onNext(result);

           }
       }).subscribeOn(Schedulers.io())
               .observeOn(AndroidSchedulers.mainThread())
               .subscribe(new Observer<String>() {

            @Override
            public void onSubscribe(@NonNull Disposable disposable) {
                Log.i(TAG,"onSubscribe");
            }

            @Override
            public void onNext(@NonNull String s) {
                        Log.i(TAG,"onNext login result s:"+s);
                        check_login_result(s);
            }

            @Override
            public void onError(@NonNull Throwable throwable) {

            }

            @Override
            public void onComplete() {

            }
        });

when it run, it will crash ,and log is

E/AndroidRuntime(28386): java.lang.NoClassDefFoundError: io.reactivex.Flowable
E/AndroidRuntime(28386):    at io.reactivex.Observable.bufferSize(Observable.java:126)
E/AndroidRuntime(28386):    at io.reactivex.Observable.observeOn(Observable.java:8545)
...................
E/AndroidRuntime(28386):    at android.view.View.performClick(View.java:4438)
E/AndroidRuntime(28386):    at android.view.View$PerformClick.run(View.java:18438)
E/AndroidRuntime(28386):    at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime(28386):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime(28386):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(28386):    at android.app.ActivityThread.main(ActivityThread.java:5008)
E/AndroidRuntime(28386):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28386):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(28386):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:807)
E/AndroidRuntime(28386):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:623)
E/AndroidRuntime(28386):    at dalvik.system.NativeStart.main(Native Method)
2.x Android Question StackOverflow

Most helpful comment

Change observeOn(AndroidSchedulers.mainThread()) to .observeOn(AndroidSchedulers.mainThread(),false,100),It would be work out,God bless you!

All 4 comments

Your project setup is likely wrong and I don't understand why you can't go with the default gradle dependency setup. Also you should ask this question on StackOverflow where more experienced Android developers frequent.

This seems like a proguard issue and not related to RxJava itself.
You have to check if your proguard is cleaning up more stuff than it should and how does it behave with your custom jar, and adapt the rules, especially if that jar has something changed compared to the standard rx lib.
Normally you dont need specific proguard rules for 2.x but like akarnokd said this is an Android problem and not an Rx one and is related to proguard and/or multidex.

Looks like this question has been answered. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.

Change observeOn(AndroidSchedulers.mainThread()) to .observeOn(AndroidSchedulers.mainThread(),false,100),It would be work out,God bless you!

Was this page helpful?
0 / 5 - 0 ratings