无法解析符号 NameValuePair

Cannot resolve symbol NameValuePair

在我的项目中出现错误:

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

然后我尝试用这个修复它:

compileSdkVersion 23

但是我得到了错误:

cannot resolve symbol NameValuePair android

如何解决这个错误?

NameValuePair 是软件包 org.apache 的一部分,它已被 Android 22 弃用并被 Android M 删除,这是您正在编译的版本。有趣的是 NameValuePair 的文档都无法访问

我遇到了同样的问题。为了解决它,我使用了:

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

还添加了

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'

到 app/gradle 依赖项。希望对您有所帮助

如果您想在 android 工作室中使用 NameValuePairBasicNameValuePair 最新的 API 关卡。然后按照以下步骤操作:

  • 打开 build.gradle(模块)文件并复制这些依赖项:

    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:+'
    
  • 复制useLibrary 'org.apache.http.legacy'下方buildToolsVersion喜欢:

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

就是这样。现在只需同步 gradle 个文件。

注意:在依赖项中我建议使用最新版本的库而不是+符号。

今天我也遇到了同样的问题。我通过 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'

我的最终 build.gradle 文件:

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'

        }

添加这个:

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

在基于应用程序的 build.gradle 中它会拾取它

有同样的问题

解决方法如下:

  1. 在依赖项中添加:

编译组:'org.apache.httpcomponents',名称:'httpclient-android',版本:'4.3.5.1'

  1. 在 defaultConfig 的 targetSdkVersion 下面添加这个

useLibrary 'org.apache.http.legacy'

嵌套 class 可行:

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