Gradle 构建错误。"minsdkversion 14 cannot be different than version l declared in library"?

Gradle build error."minsdkversion 14 cannot be different than version l declared in library"?

大家好我是androiddeveloping.I下载最新版本的androidstudio 1.3.2yesterday.But当我开始一个新项目进行测试时,gradle给我一个错误。 我的 gradle 是

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "23.0.1"

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

      dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.+'

}

错误是

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be different than version L declared in library [com.android.support:appcompat-v7:21.0.0-rc1]   C:\Users\Niyamat\Documents\Testing3\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7.0.0-rc1\AndroidManifest.xml

我知道有一些关于相同错误的问题,但我没有找到任何好的解决方案。 所以请有人帮助我?

似乎你有一个以前版本的应用程序兼容到你的 lib 文件夹特定于 android L.

此外,您应该将 compileSdkVersionbuildToolVersiontargetSdkVersionappcompat-v7 的版本设置为相同。

在您的情况下,buildToolVersion 应该是“21.1.2”。

基本上,这就是为什么 android 工作室抱怨/建议 不要 在你的编译中使用 .+ 的原因。

compile 'com.android.support:appcompat-v7:21.+'

它强制使用绝对最新版本的 appcompat 21 进行编译,即 com.android.support:appcompat-v7:21.0.0-rc1(正如您从错误中看到的那样)。该版本不允许 minSdkVersion 15 - 它是为 Lollipop 制作的。将您的编译应用程序兼容性更改为允许 minSdkVersion 15 解决问题的版本号。

你的 Logcat 投了多少

 Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be different than version L declared in library [com.android.support:appcompat-v7:21.0.0-rc1]

你应该做什么

  1. Manifest 中删除 minSdkVersion 版本。您已经在 build.gradle 中声明了它。
  2. 用这个 compileSdkVersion 21 buildToolsVersion '21.1.2' 代替你的。
  3. 编译compile 'com.android.support:appcompat-v7:21.0.1'

首先从您的 Manifest 中删除这一行。

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

终于

    apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

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

      dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.1'

}

这是你的问题。

uses-sdk:minSdkVersion 15 cannot be different than version L declared in library [com.android.support:appcompat-v7:21.0.0-rc1]

很奇怪,您的 sdk 文件夹中有 appcompat 21 的预览版。 此版本与棒棒糖预览版 (api-L) 一起发布,并具有 minSdk = L。这是您问题的原因(因为您有 minSdkVersion 15

您的 sdk 中不应包含此文件夹。检查 SDK 管理器 是否已更新。

然后你可以修改你的 build.gradle 删除 +.

支持库 v21

compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:appcompat-v7:21.0.3'

支持库 v22(需要 compileSdkVersion 22)

compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.1'

支持库v23(需要compileSdkVersion 23)

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