org.apache.http.NameValuePair在compileSdkVersion 23中不再可用 [英] org.apache.http.NameValuePair no longer available with compileSdkVersion 23
问题描述
我有一个请求功能的帮助程序类,下面是我使用的一种方法.
I have a helper class that does request functions, and one method I am using is the following.
private String buildQueryString(String url, List<NameValuePair> params) throws IOException {
StringBuilder sb = new StringBuilder();
if (params == null) return url;
for (NameValuePair param : params) {
sb.append(urlEncode(param.getName()));
sb.append("=");
sb.append(urlEncode(param.getValue()));
sb.append("&");
}
return url + "?" + sb.substring(0, sb.length() - 1);
}
如果我将gradle更新为compileSdkVersion 23,则导入org.apache.http.NameValuePair将不再存在.我很好奇,知道替代品是什么?预先感谢!
If I update my gradle to compileSdkVersion 23, the import org.apache.http.NameValuePair no longer exists. I was curious to know what the replacement is? Thanks in advance!
编辑-发布gradle-另外,我正在使用gradle-2.4
EDIT -posting gradle- Also, I am using gradle-2.4
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
signingConfigs {
debug {
storeFile file('keystore/debug/debug.keystore')
}
}
compileSdkVersion 23
buildToolsVersion "21.1.2"
useLibrary 'org.apache.http.legacy'
// jenkins setup
def versionPropsFile = file('version.properties')
def code = 1;
if (versionPropsFile.canRead() && versionPropsFile.exists()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
List<String> runTasks = gradle.startParameter.getTaskNames();
def value = 0
for (String item : runTasks) {
if (item.contains("assembleRelease")) {
value = 1;
}
}
code = Integer.parseInt(versionProps['VERSION_CODE']).intValue() + value
versionProps['VERSION_CODE'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
} else {
throw new GradleException("Could not read version.properties!")
}
// construct version name
def versionMajor = 2
def versionMinor = 3
def versionPatch = 9
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
versionCode code
signingConfig signingConfigs.debug
// enabling multidex support
multiDexEnabled true
}
buildTypes {
stage {
<content removed>
}
debug {
<content removed>
}
release {
<content removed>
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
dependencies {
<bunch of dependencies>
compile 'com.android.support:support-v4:23.0.1'
}
推荐答案
将此内容添加到您的build.gradle
Add this on your build.gradle
android {
useLibrary 'org.apache.http.legacy'
}
org.apache库已从api 22中弃用,并已在api 23中被淘汰.
org.apache library was deprecated from api 22 and it was eliminated on api 23.
用buildToolsVersion '23.0.1'
或者您应该在依赖项上添加它:
Or you should add this on your dependencies:
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
请小心使用Gradle 1.3.+
Be careful to use the Gradle 1.3.+
这篇关于org.apache.http.NameValuePair在compileSdkVersion 23中不再可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!