在我的项目中出现了一个错误:
Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'。
然后我尝试使用以下方法进行修复:
compileSdkVersion 23
但是我遇到了错误:
无法解析符号NameValuePair android
如何修复这个错误?
如果您想在最新的API级别下在Android Studio中使用NameValuePair或BasicNameValuePair,请按照以下步骤进行:
打开build.gradle(Module)文件并复制以下依赖项:
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:+'
在 buildToolsVersion
下方加入 useLibrary 'org.apache.http.legacy'
,如下所示:
android {
useLibrary 'org.apache.http.legacy'}
就这些了。现在只需同步 Gradle 文件即可。
注意:在依赖项中,我建议使用最新版本的库,而不是使用 + 符号。
NameValuePair
是org.apache
包的一部分,该包在Android 22
中被弃用并在Android M
中被删除,而您正在编译的版本正是该版本。有趣的是,NameValuePair文档也无法访问。
org.apache.http
中的 NameValuePair
和 BasicNameValuePair
。 - g8214435今天我也遇到了同样的问题。我通过在我的 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'
嵌套类将有效:
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;
}
};
我也遇到了同样的问题。为了解决它,我使用了以下方法:
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'
添加到应用程序/Gradle依赖项中。希望这有所帮助。
遇到了同样的问题
解决方法如下:
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
useLibrary 'org.apache.http.legacy'