I’m working on an Android app that needs to connect to the Spoonacular API through RapidAPI. I’m using Unirest for HTTP requests but keep running into a class resolution error.
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 am I missing in my setup? Any suggestions on how to resolve this dependency issue would be great.
This happens because Unirest depends on Apache HttpAsyncClient, which requires NIO reactor classes that Android’s stripped-down Apache HTTP library doesn’t include. Even with the legacy library enabled, Android misses the async/NIO components where DefaultConnectingIOReactor is found. I encountered this same issue with another RapidAPI service previously. The simplest solution is to replace Unirest with another HTTP client; OkHttp is a great choice for RapidAPI calls and is well-supported on Android. You can change your Unirest call to use OkHttp like this: OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=chicken%2Crice&number=10&ranking=2").addHeader("X-Mashape-Key", "my-api-key").addHeader("X-Mashape-Host", "spoonacular-recipe-food-nutrition-v1.p.mashape.com").build();. This eliminates dependency conflicts and OkHttp adequately manages JSON responses without significant additional code.
yeah, this is a pain with unirest on android. the nio reactor classes dont exist in apaches android libs. just drop unirest and use volley or retrofit instead - theyll work better and you wont deal with these dependency headaches.
Same issue here. Unirest uses HttpAsyncClient internally, which needs the full Apache HTTP stack. Android only gives you a subset through its legacy library. You might think adding httpasyncclient as a dependency fixes it, but that usually creates more conflicts because of version mismatches with Android’s bundled stuff. I switched to Retrofit with Gson converter instead. Works perfectly with RapidAPI endpoints and the setup’s way cleaner. Just create a service interface with @GET and @Header parameters, then run it through the Retrofit client. Way more reliable than dealing with Apache’s dependency mess on Android.