ReactiveX / RxJava

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
Apache License 2.0
47.88k stars 7.61k forks source link

java.lang.NoClassDefFoundError: io.reactivex.Flowable #5336

Closed yangmao1986 closed 7 years ago

yangmao1986 commented 7 years ago

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)
akarnokd commented 7 years ago

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.

originx commented 7 years ago

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.

akarnokd commented 7 years ago

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.

TrillGates commented 7 years ago

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