I’m working on an Android app and trying to connect to a food recipe API using the Unirest library. I’ve followed the instructions for setting up Unirest without Maven, and I’ve added the jar file to my project.
Here’s my gradle configuration:
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
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'
}
And here’s my API call code:
HttpResponse<JsonNode> apiResponse = null;
try {
apiResponse = Unirest.get("https://recipe-api.example.com/search?query=chicken,rice&limit=10")
.header("X-API-Key", "my_api_key")
.header("X-API-Host", "recipe-api.example.com")
.asJson();
} catch (UnirestException ex) {
ex.printStackTrace();
}
However, I’m encountering a crash when the app attempts to make the request. The error indicates that the DefaultConnectingIOReactor class cannot be found. Has anyone experienced this before? What could I be missing in my configuration?