I’m encountering a crash when utilizing the Unirest HTTP client in my Android application to interact with a food recipe API. The issue arises immediately upon making my first API request.
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/impl/nio/reactor/DefaultConnectingIOReactor;
at com.mashape.unirest.http.options.Options.refresh(Options.java:85)
at com.mashape.unirest.http.options.Options.<clinit>(Options.java:46)
What steps can I take to resolve this missing class issue? I have followed the setup instructions, but it seems like there’s something else I might be overlooking.
Had this exact problem last week! You’re missing the httpcore-nio dependency that unirest needs. Add implementation 'org.apache.httpcomponents:httpcore-nio:4.3.3' to your gradle file - fixed it for me. But honestly, unirest’s pretty outdated for Android. Retrofit with Gson is way cleaner.
This happens because Unirest doesn’t play nice with Android. The DefaultConnectingIOReactor class is part of Apache HttpComponents, which conflicts with Android’s built-in HTTP libraries. Adding the missing dependencies won’t fix it - you’ll just hit more runtime issues since Android’s networking works differently than regular Java. I ran into the same thing migrating old code. Unirest was built for servers, not mobile apps. The useLibrary 'org.apache.http.legacy' fix is deprecated and breaks on newer Android versions anyway. Just switch to Volley if you want something simple, or OkHttp for more features. Both are made for Android and handle networking way better without these headaches.
Been there with the dependency hell. Sure, you could add the missing httpcore-nio package like others mentioned, but you’re just patching an old, clunky solution.
Had a similar API integration nightmare last year. Spent hours wrestling with Apache dependencies until I realized I was overcomplicating everything.
Why not automate the whole API workflow? Set up Latenode to handle your recipe API calls, data transformation, and caching. Create a simple webhook endpoint that your Android app hits instead of dealing with all these HTTP client libraries.
Built something similar where Latenode fetches data from multiple recipe APIs, cleans it up, and serves it through one clean endpoint. No more dependency conflicts, no outdated libraries, and your app gets consistent data every time.
You can also add rate limiting, response caching, and data enrichment without touching your mobile code.
The crash occurs due to Unirest requiring the Apache HttpAsyncClient, which is dependent on the NIO reactor classes. Specifically, the DefaultConnectingIOReactor class is part of httpcore-nio, which is absent from your current setup. I faced a similar issue when updating an older project. Unirest relies on the complete Apache HttpComponents stack, while httpclient-android offers only the basic components. To resolve the crash, include httpcore-nio in your Gradle file. However, note that Google has deprecated support for the Apache HTTP client in newer Android versions, which makes it a less viable option going forward. I recommend switching to OkHttp or Retrofit, as they are optimized for Android, perform better, and typically allow for an easier migration.