I have the following gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
}
defaultConfig {
applicationId "com.guesstheurf.guesstheurf"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile (
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.5.0'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.5.0'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.5.0']
)
compile ('org.apache.httpcomponents:fluent-hc:4.4.1')
}
When I build this, I get warnings stating
Dependency
org.apache.httpcomponents:httpclient:4.4.1
is ignored for release as it may be conflicting with the internal version provided by Android.
This is a dependency relied on by httpcomponents:fluent-hc
.
I found this source on dependency management(chapter 51.4.7: Excluding transitive dependencies) that indicates I can just exclude the transitive dependency that causes the conflict.
However when I change it to
compile ('org.apache.httpcomponents:fluent-hc:4.4.1') { exclude module: 'httpclient' }
the Gradle warning is indeed gone, but the problem still persists:
Caused by: java.lang.NoClassDefFoundError: org.apache.http.client.fluent.InternalEntityEnclosingHttpRequest at org.apache.http.client.fluent.Request.Post(Request.java:95)
The issue stays when I use
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
as indicated in this answer.
When I use
configurations {
all*.exclude module: 'httpclient'
}
the warning is gone as well, though the runtime error persists.
This source which suggests to force my own version using force = true
doesn't fix the issue either.
Explicitly adding the httpclient-related dependencies as suggested here doesn't work either (and doesn't remove the warnings):
compile 'org.apache.httpcomponents:httpclient:4.4.1'
compile 'org.apache.httpcomponents:fluent-hc:4.4.1'
compile "org.apache.httpcomponents:httpmime:4.4.1"
compile 'org.apache.httpcomponents:httpcore:4.4.1'
How can I get fluent-hc to work? And why doesn't it simply select the newest version of the httpclient package since that is the default resolution strategy according to 51.2.3 Resolve version conflicts?