从API级别23切换到22时出现错误

4

我想在Android Studio中将最小SDK版本从API 23更改为API 22,因为API 23不支持HttpClient。我尝试在build.gradle(Module:app)中进行更改,即将compileSdkVersion从23更改为22,将targetSdkVersion从23更改为22。

android {
compileSdkVersion 23
buildToolsVersion "22.0.1"

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

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile project(':android-query-full.0.26.7')
compile 'com.loopj.android:android-async-http:1.4.8'
}

然后,同步并重建项目。但是我在Gradle控制台中遇到了以下错误。
AGPBI: {"kind":"error","text":"Error retrieving parent for item: No resource found that matches the given name \u0027android:TextAppearance.Material.Widget.Button.Inverse\u0027.","sources":[{"file":"C:\\Users\\nischal.manandhar\\AndroidStudioProjects\\GCMGreetingApp\\app\\build\\intermediates\\exploded-aar\\com.android.support\\appcompat-v7\\23.0.0\\res\\values-v23\\values-v23.xml","position":{"startLine":1}}],"original":""}
AGPBI: {"kind":"error","text":"Error retrieving parent for item: No resource found that matches the given name \u0027android:Widget.Material.Button.Colored\u0027.","sources":[{"file":"C:\\Users\\nischal.manandhar\\AndroidStudioProjects\\GCMGreetingApp\\app\\build\\intermediates\\exploded-aar\\com.android.support\\appcompat-v7\\23.0.0\\res\\values-v23\\values-v23.xml","position":{"startLine":1}}],"original":""}


FAILED

FAILURE: Build failed with an exception.

错误出现在文件v23\values-v23.xml中。

非常感谢您的帮助。谢谢!!!


HttpClient已被弃用。 - Skynet
是的,但它在API 22级上运行良好,现在在23级上不起作用了!! - Nischal
尝试使用HttpUrlConnection - 它得到了更多的支持并且适用于所有API版本 :) - Skynet
6个回答

2

尝试更改:

compile 'com.android.support:appcompat-v7:23.0.0'

为:

compile 'com.android.support:appcompat-v7:22.2.0'

并将compileSdkVersiontargetSdkVersion设置为22


2

在您的 AndroidManifest.xml 中更改它

    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

干杯


这是最糟糕的答案,请不要听从它。 - Jonathan Vukadinovic

2
使用这个:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "au.com.websutra.gcmgreetingapp"
    minSdkVersion 11
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile project(':android-query-full.0.26.7')
compile 'com.loopj.android:android-async-http:1.4.6'
}

@Nischal 继续前进。如果有帮助,请投赞成票。 - IntelliJ Amiya

2
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "au.com.websutra.gcmgreetingapp"
    minSdkVersion 11
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile project(':android-query-full.0.26.7')
compile 'com.loopj.android:android-async-http:1.4.8'
}

注意:将文件夹名称从“values-v23”更改为“values-v22”


1

经过一些研究,我成功地在API 23中使用org.apache.http.legacy.jar库使Apache HTTP客户端工作。以下配置起作用。

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

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

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile project(':android-query-full.0.26.7')
compile 'com.loopj.android:android-async-http:1.4.8'
compile files('libs/org.apache.http.legacy.jar')
} 

我手动将 org.apache.http.legacy.jarAndroid/Sdk/platforms/android-23/optional 文件夹复制到我的项目中的 app/libs 文件夹中,然后添加了以下内容:

useLibrary 'org.apache.http.legacy'  

在 Android 标签内部{...}。

你的问题是将compileSdkVersion从23切换到22!!而你回答了如何使HttpClient适用于目标api 23?! - shadygoneinsane

1
错误是因为您使用了sdk版本23构建工具22.0.1。更新构建工具到最新版本(也要下载它们)。以下是配置:
android {
  compileSdkVersion 23
  buildToolsVersion "23.0.0"

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

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  compile 'com.android.support:appcompat-v7:23.0.0'
  compile 'com.google.android.gms:play-services:7.8.0'
  compile project(':android-query-full.0.26.7')
  compile 'com.loopj.android:android-async-http:1.4.8'
}

更新::在async-http库更新之前,您可以使用以下方法:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接