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 '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'
}
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.client:4.1.2'
Be careful to use the Gradle 1.3.+
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:
https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client
Latest android gradle plugin changelog: http://tools.android.com/tech-docs/new-build-system
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'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With