0

我想在我的cordova项目中添加以下依赖项。但是,构建过程中依赖项会被忽略。Android Gradle依赖关系

compile 'org.apache.httpcomponents:httpclient:4.5.2' 

从类似问题的答案,我意识到我已经排除了几个模块和组。

所以我对依赖关系做了如下修改。

compile 'org.apache.httpcomponents:httpclient:4.5.2' 
compile ('org.apache.httpcomponents:httpclient:4.5.2'){ 
    exclude module: 'httpclient' //by artifact name 
    exclude group: 'org.apache.httpcomponents' //by group 
    exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group 
} 

不过,我仍然得到此警告。

WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it 
may be conflicting with the internal version provided by Android. 
In case of problem, please repackage it with jarjar to change the class packages. 

由于这样,我的所有HTTP命令,如HTTP POST,HTTP客户端等都没有解决。

有人可以建议我究竟要排除什么,以及是否需要更改配置?

回答

3

您可以通过加入这一行使用HTTP库建立您的应用程序的脚本:

useLibrary 'org.apache.http.legacy' 

像:

android { 
    compileSdkVersion XX 
    buildToolsVersion "XX.X.X" 

    useLibrary 'org.apache.http.legacy' 

    // other lines 
} 

希望这有助于:)

+0

确保你在正确的build.gradle文件中完成它。我在Google LVL上遇到了这个问题,但一直把它放在应用程序的build.gradle中 – Oded

1

使用适合各自android版本的Apache http客户端的重新打包版本。

对于Android的API 22岁以上

dependencies { 
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1' 
} 

对于Android的API 23和新

dependencies { 
    compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1' 
} 

此连结更多信息 - https://hc.apache.org/httpcomponents-client-4.5.x/android-port.html

+0

我有+1了这个太早了。我得到的错误: 找不到符号类的NameValuePair 找不到符号变量URLEncodedUtils 找不到符号类的NameValuePair 即使有新的依赖 – Oded

+0

@Oded我猜你仍然缺少一些依赖。 – Gandhi

+0

我想我可能已经把依赖项放在错误的build.gradle文件中。 – Oded