Caused by: java.lang.NoClassDefFoundError: org.apache.http.util.Args

你说的曾经没有我的故事 提交于 2019-12-13 18:37:29

问题


  conn.addRequestProperty(entity.getContentType().getName(), entity.getContentType().getValue());

It crashes on samsung device running operating system version 4.1. While on Marshmallow Nexus 6 device, it works perfectly fine. What is the problem?

Gradle file

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

I have in my libs folder httpclient-4.3.3.jar httpclient-cache-4.3.3.jar httpcore-4.3.2.jar httpmime-4.3.3.jar


回答1:


Apache http client was removed since marshmallow.

See here Apache HTTP Client Removal

Solution (about embed client at all):

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

UPDATED: About the particular problem see related post

Btw, in my project I can't add apache http client as a library, because of package name conflict with embed cliend. I have to use this or as described here




回答2:


Please include useLibrary url like this

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



回答3:


For Marshmallow Apache HTTP Client Removal

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

}

try this once

app/build/libs Files >> Project Structure >> Dependencies >> + >> File Dependencies >> and then change it to provided instead of compile (compile will cause a java exit with nonzero value 1 if you are importing too much jars.

Samsung has customised the sdk so there are channces to include more jars..



来源:https://stackoverflow.com/questions/36127232/caused-by-java-lang-noclassdeffounderror-org-apache-http-util-args

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!