android - 获取失败的解决方案:Lorg/apache/http/impl/nio/reactor/DefaultConnectingIOReactor 尝试从 RapidAPI 实现 Unirest API 时
问题描述
我正在尝试使用 Android 实现 RapidApi 的 Spoonacular Api。它使用 Unirest,所以我正在尝试配置它。在官方文档中,我正在关注该Without Maven
部分。我下载了 unirest jar,我的里面有这些build.gradle
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'
这是我的java代码:
HttpResponse<JsonNode> response = null;
try {
response = Unirest.get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=egg%2Cyogurt&number=5&ranking=1")
.header("X-Mashape-Key", "keyyy")
.header("X-Mashape-Host", "spoonacular-recipe-food-nutrition-v1.p.mashape.com")
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
我收到此错误:
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)
你能帮我弄清楚如何解决这个问题吗?谢谢
解决方案
我相信您错过了其中一个Apache 依赖项(httpasyncclient
我想在您的情况下)。
正如文档中提到的那样,实际上有三个:
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
因此,请转到此链接下载 - 在您的项目中手动添加 jar 文件:
http://hc.apache.org/downloads.cgi
并寻找:HttpAsyncClient
。
使用它jar
在项目中添加文件库:How to add a jar in External Libraries in android studio
推荐阅读
- amazon-s3 - 使用 AWS Data Pipeline 将数据从 AWS RDS 移动到 S3
- r - 从一个数据帧中提取变量列表并将其应用于另一个数据帧
- javascript - 如何显示来自 mongodb 的关系数据
- git - 如何使用 bfg 减小 git 存储库的大小
- javascript - 按键退出按钮状态上的全屏按钮不会更改为关闭
- php - 对 XMLHttpRequest 的 Flutter Web 访问已被 CORS 策略阻止
- javascript - React material-ui textfield decimal step 1.00 on 1.00 作为默认数字
- excel - 根据值将 1 个长 excel 列拆分为多个列
- sql - SQL 将 nvarchar 转换为 int
- qt - 具有自己的子小部件(按钮)和背景图像的 QWidget 不起作用