Cannot resolve symbol NameValuePair

亡梦爱人 提交于 2019-12-17 10:54:21

问题


In my project I got an error:

Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

Then I tried to fix it use this:

compileSdkVersion 23

But then I got error:

cannot resolve symbol NameValuePair android

How to fix this error?


回答1:


NameValuePair is part the package org.apache which was deprecated with Android 22 and removed with Android M, which is the version against you are compiling. What is interesting is that neither the documentation of NameValuePair is reachable




回答2:


If you want to use NameValuePair or BasicNameValuePair in android studio with latest API Levels. Then follow steps below:

  • Open build.gradle(Module) file and copy these dependencies:

    implementation 'com.google.http-client:google-http-client-android:+'
    
    implementation 'com.google.api-client:google-api-client-android:+'
    
    implementation 'com.google.api-client:google-api-client-gson:+'
    
  • Copy useLibrary 'org.apache.http.legacy' below buildToolsVersion like:

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

Thats all. Now just sync gradle file.

Note: In dependencies i recommend to use latest version of libraries instead of + symbol.




回答3:


Today i also had same problem. I solved with two changes in my build.gradle

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

2)  compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'

My final build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.corouter"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

android {
    useLibrary 'org.apache.http.legacy'
}
dependencies
        {
            compile fileTree(include: ['*.jar'], dir: 'libs')
            testCompile 'junit:junit:4.12'
            compile 'com.android.support:appcompat-v7:23.2.0'
            compile 'com.android.support:recyclerview-v7:23.0.+'
            compile 'org.apache.httpcomponents:httpcore:4.4.1'
            compile 'org.apache.httpcomponents:httpclient:4.5'

        }



回答4:


add this:

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

in app based build.gradle it will pick it up




回答5:


Nested class would work:

private class NameValuePair {
        private String mName;
        private String mValue;

        public NameValuePair(String name, String value) {
            mName = name;
            mValue = value;
        }

        public String getName() {
            return mName;
        }

        public String getValue() {
            return mValue;
        }
    };



回答6:


I was facing the same issue. To resolve it, I used:

import cz.msebera.android.httpclient.NameValuePair;
import cz.msebera.android.httpclient.message.BasicNameValuePair;

and also added

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "cz.msebera.android:httpclient:4.4.1.1"
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'

to the app/gradle dependencies. I hope that helps




回答7:


Had the same problem

Solved it as follows:

  1. Add this in dependencies:

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'

  1. Add this below targetSdkVersion in defaultConfig

useLibrary 'org.apache.http.legacy'



来源:https://stackoverflow.com/questions/32121031/cannot-resolve-symbol-namevaluepair

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