android - SDK :minSdkVersion 15 cannot be different than version L declared in library

标签 android android-gradle-plugin

构建我的应用程序时出现以下错误

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be different than version L declared in library C:\Users\Sybren-PC\AndroidStudioProjects\Tutorial\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.0-rc1\AndroidManifest.xml

我在 build.gradle 中尝试了一些东西,但似乎没有任何效果。

错误信息指向这个文件

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.support.v7.appcompat" >

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

    <application />

</manifest>

AndroidManifest.xml(来 self 的项目)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sybren_pc.tutorial" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Build.gradle(模块:应用程序)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.sybren_pc.tutorial"
        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.+'

}

谁能帮忙解决这个问题?

编辑

这就是我的 build.gradle 现在的样子。 gradle 构建现在可以了。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.sybren_pc.tutorial"
        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.0'

我从 SDK 管理器进行的更新:Android SDK 构建工具、Android 支持存储库、Android 支持库

最佳答案

首先,您在 Manifest.xml 中声明

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

您可以完全删除这些行,因为 Gradle 覆盖了 Manifest 的值,因此您只能在 Gradle 中指定版本(Source ).

错误的发生是因为 build.gradle 中的 compileSdkVersion 低于 Manifest.xml 中声明的 - 它会提示这一点。

第二件事是:在 build.gradle 中,您使用 buildToolsVersion = 20.0.0,但您希望针对 SDK 版本 编译它 = 21. 它不能。您应该通过 SDK Manager 更新 BuildTools。 这是关于最新的 Build Toolsdoc 以及值得一看的 article。很好的解释。

希望这能解决您的问题。干杯。

关于android - SDK :minSdkVersion 15 cannot be different than version L declared in library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004479/

相关文章:

java - 在 Activity 之间传递 ResourceId 作为整数

java - Android 在闹钟管理器中设置特定时间和日期

android - 作为 RecyclerView 的 ViewHolder 的 fragment ?

android - Build.Gradle 错误 : Unable to resolve dependency

不独立滚动的Android多个 ListView

java - 具有返回接口(interface)的 Android 中的 AsyncTask

android - 如何使用更新版本的 gradle 构建 Android 项目?

android - zip.ZipException : duplicate entry: annotations/Beta. 类

android - 找不到 Gradle DSL 方法 : 'compile() The project ' android' may be using a version of Gradle that does not contain the method

android - 对 Android Gradle 中的 testCompile 和 androidTestCompile 感到困惑