Gradle 没有选择正确的 appcompat-v7:22.2.1

Gradle not picking right appcompat-v7:22.2.1

我遇到了一个奇怪的问题,我安装了最新的 appcompat-v7:23.0.0 我知道我一定不需要它,但我需要使用 appcompat-v7:22.2.1 或 appcompat-v7:22.0.0

我根据需要更新了我的 gradle,但它总是选择不需要的 appcompat-v7:23.0.0,有人指导我如何解决这个问题吗?

AppCompat (aka ActionBarCompat) started out as a backport of the Android 4.0 ActionBar API for devices running on Gingerbread, providing a common API layer on top of the backported implementation and the framework implementation. AppCompat v21 delivers an API and feature-set that is up-to-date with Android 5.0

您可以使用

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

终于

android {
compileSdkVersion 22
buildToolsVersion '22.0.1' // You can set  buildToolsVersion '23.0.1' 

建议

你应该使用

compile 'com.google.android.gms:play-services:7.8.0' // or 8.4.0

Good Approach : 使用最新版本 .

you need to download the latest support repository from internal SDK manager of Android Studio or from the stand alone SDK manager. Then you can add compile 'com.android.support:appcompat-v7:23.0.1'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId ""
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

dependencies {

    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services:7.8.0' // or 8.4.0
}

编辑

您可以使用这个类路径

classpath 'com.android.tools.build:gradle:1.3.0'

然后 清理-重建-重新启动-同步 您的项目。希望这有帮助。

因为您正在使用

compile 'com.google.android.gms:play-services:+'

您使用的是最新版本 compile 'com.google.android.gms:play-services:8.4.0',它依赖于支持库 v23

您必须使用 API 23.

进行编译

更改此行:

 compileSdkVersion 23

如果你不想使用 api23,你可以使用像 as

这样的特定版本
compile 'com.google.android.gms:play-services:7.8.0' 

一般来说,在你的依赖中使用 +不是一个好习惯,因为你不能在未来使用相同的库复制构建,你不知道你用的是哪个版本。

另外您可以将 api23 与 Httpclient 一起使用。
只需使用:

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

更多info here.

useLibrary 需要 gradle 插件 1.3.0 (classpath 'com.android.tools.build:gradle:1.3.0') 或更高版本。