Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

org.apache.http.NameValuePair no longer available with compileSdkVersion 23

Writer Matthew Harrington

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);
}

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!

EDIT -posting gradle- Also, I am using gradle-2.4

buildscript { repositories { maven { url ' } maven { url ' } } dependencies { classpath 'io.fabric.tools:gradle:1.+' }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories { maven { url ' }
}
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'
}

2 Answers

Add this on your build.gradle

android { useLibrary 'org.apache.http.legacy'
}

org.apache library was deprecated from api 22 and it was eliminated on api 23.

change buildToolsVersion '21.1.2' with 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.cli‌​ent:4.1.2'

Be careful to use the Gradle 1.3.+

7

To elaborate on this issue, there are two ways to fix this for those that face the same conflict. As @Michele pointed out, useLibrary 'org.apache.http.legacy' can be used, but you have to remember to also update gradle.

For API 23:

Top level build.gradle - /build.gradle

buildscript { ... dependencies { classpath 'com.android.tools.build:gradle:1.3.1' }
}
...

Module specific build.gradle - /app/build.gradle

android { compileSdkVersion 23 buildToolsVersion "23.0.0" useLibrary 'org.apache.http.legacy' ...
}

Official doc:

Latest android gradle plugin changelog:

The second way of resolving this is by adding the following to dependencies

 dependencies { compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' }

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.