2

I've an Android project where I used rxjava and rxAndroid. I suddenly started to get that crash "NoClassDefFoundError: rx.subscriptions.CompositeSubscription"

I've tried to look it online but I couldn't find a solution

java.lang.ExceptionInInitializerError
at rx.plugins.RxJavaSchedulersHook.createIoScheduler(RxJavaSchedulersHook.java:84)
at rx.plugins.RxJavaSchedulersHook.createIoScheduler(RxJavaSchedulersHook.java:72)
at rx.schedulers.Schedulers.<init>(Schedulers.java:70)
at rx.schedulers.Schedulers.getInstance(Schedulers.java:47)
at rx.schedulers.Schedulers.newThread(Schedulers.java:108)
at com.myPackage.controllers.modelsControllers.CountriesController.loadCountries(CountriesController.java:121)
at com.myPackage.views.fragments.ChatFragment.onCreateView(ChatFragment.java:57)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)
at android.app.BackStackRecord.run(BackStackRecord.java:635)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397)
at android.app.Activity.performStart(Activity.java:5017)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: rx.subscriptions.CompositeSubscription
at rx.internal.schedulers.CachedThreadScheduler$CachedWorkerPool.<init>(CachedThreadScheduler.java:48)
at rx.internal.schedulers.CachedThreadScheduler.<clinit>(CachedThreadScheduler.java:139)
at rx.plugins.RxJavaSchedulersHook.createIoScheduler(RxJavaSchedulersHook.java:84) 
at rx.plugins.RxJavaSchedulersHook.createIoScheduler(RxJavaSchedulersHook.java:72) 
at rx.schedulers.Schedulers.<init>(Schedulers.java:70) 
at rx.schedulers.Schedulers.getInstance(Schedulers.java:47) 
at rx.schedulers.Schedulers.newThread(Schedulers.java:108) 
at com.myPackage.controllers.modelsControllers.CountriesController.loadCountries(CountriesController.java:121) 
at com.myPackage.views.fragments.ChatFragment.onCreateView(ChatFragment.java:57) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:829) 
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035) 
at android.app.BackStackRecord.run(BackStackRecord.java:635) 
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1397) 
at android.app.Activity.performStart(Activity.java:5017) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
at android.app.ActivityThread.access$600(ActivityThread.java:130) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:4745) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 

I didn't really change anything in the classes which is throwing exception which confuse me.

In my build.gradle, I've compile 'io.reactivex:rxandroid:1.2.1' compile 'io.reactivex:rxjava:1.1.6'

in my observable, I send http request using okHttp, and the exact line that throws exception is

subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread());

I need any suggestion ^^, and if you have any question please let me know.

Also if possible, can anyone explain what does that crash even mean? Thanks.

EDIT my build.gradle have those

    compile 'io.reactivex:rxandroid:1.2.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0'
    compile 'com.trello:rxlifecycle:0.6.1'
// If you want pre-written Activities and Fragments you can subclass as providers
    compile 'com.trello:rxlifecycle-components:0.6.1'

    compile 'com.mlsdev.rximagepicker:library:1.1.9'
    compile 'com.github.zellius:rxlocationmanager:0.1.1'
    compile 'com.sdoward:rxgooglemaps:1.0@aar'
M.Baraka
  • 725
  • 1
  • 10
  • 24

3 Answers3

4

If you are using multidex then also this problem might occur. But in lower version of the phones.

All you need to do is follow the procedures given over here:

https://stackoverflow.com/a/26627133/842607

Community
  • 1
  • 1
Jimit Patel
  • 4,265
  • 2
  • 34
  • 58
2

NoClassDefFoundError often happens when the build tools and/or hot-swapping fails to update after changing dependencies.

Try a Build > Clean Project and then run again.

Andrew G
  • 2,596
  • 2
  • 19
  • 26
  • I've removed compile 'io.reactivex:rxandroid:1.2.1', and cleaned, rebuild, close the android studio, launch it again, and tried to delete all folders under .gradle\caches\modules\files-2.1 folder, i still get same crash. Also if i try to use new CompositeSubscription, it crashes. but i can actually open that class and see what is it...... – M.Baraka Aug 02 '16 at 11:44
  • try updating to latest rx-java `1.1.8` – Andrew G Aug 02 '16 at 11:53
  • Okay, I've tried the same code on different pc and it is working, so i assume something locally screwed for me. – M.Baraka Aug 02 '16 at 18:51
  • Yeah, usually a clean build will sort it, otherwise turning instant run off (or uninstalling the app) can help. – Andrew G Aug 02 '16 at 23:03
1

Okay, I can explain how I tried to fix, and hopefully it helps someone. I tried clean > rebuild few times, I've removed my libraries which was installed in c:users\userName.gradle\caches\modules\files-2.1, then tried to check dependencies to see if there is duplicates (some libraries can include each other internally), and I always cleaned and rebuilt. In the end I re-downloaded the whole Android environment.

However, for some reason, I remembered i didn't apply the multidex and i did it, and it worked, and that what worked for me. Which i still don't understand why, because it worked on different pc without multidex

M.Baraka
  • 725
  • 1
  • 10
  • 24
  • I am using multidex currently. Does it impact rx library?? Because for me it's very peculiar. It's not repeating the error in every device. From the devices which I have I am facing this is Panasonic P55 Novo. Not in any of others like Mototrola Nexus 6, Mi4I, Mi5, Redmi, Mi Max, HTC One M9+... – Jimit Patel Nov 14 '16 at 08:31
  • Ok found the problem... didn't used support for multidex. Your keyword multidex helped me out. thanks :) – Jimit Patel Nov 14 '16 at 08:42
  • Adding Multidex support also fixed the problem for me... Thanks ! – Phil Jan 13 '17 at 09:31