Issue Overview
I am attempting to utilize the Spoonacular API from RapidAPI within my Android application, and I am configuring it to work with Unirest. Following the guidelines in the Without Maven section of the Unirest documentation, I downloaded the Unirest JAR file and made the following modifications to my build.gradle
file:
apply plugin: 'com.android.application'
android {
...
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
...
implementation 'com.rapidapi:rapidconnect-android:0.1'
implementation files('libs/unirest-java-1.4.9.jar')
implementation 'org.json:json:20171018'
implementation('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'
}
apply plugin: 'com.google.gms.google-services'
The Java code I am working with is as follows:
HttpResponse<JsonNode> result = null;
try {
result = Unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=egg,yogurt&number=5&ranking=1")
.header("X-Mashape-Key", "your_api_key_here")
.header("X-Mashape-Host", "spoonacular-recipe-food-nutrition-v1.p.mashape.com")
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
However, I am encountering the following error:
09-19 11:53:19.674 6789-6789/com.example.hassen.androidpim E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hassen.androidpim, PID: 6789
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)
at com.mashape.unirest.http.options.Options.getOption(Options.java:42)
Could anyone guide me on how to resolve this issue? I appreciate any assistance.