【问题标题】:sdk:minSdkVersion 15 cannot be different than version L declared in librarysdk:minSdkVersion 15 不能与库中声明的版本 L 不同
【发布时间】:2015-05-02 16:07:11
【问题描述】:

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

错误:任务 ':app:processDebugManifest' 执行失败。

清单合并失败:uses-sdk:minSdkVersion 15 不能与库 C:\Users\Sybren-PC\AndroidStudioProjects\Tutorial\app\build\intermediates\exploded-aar\com.android.support 中声明的版本 L 不同\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(来自我的项目)

<?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(模块:app)

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 支持库

【问题讨论】:

  • 没有理由再次使用预览-L,使用api 22
  • 你使用的是哪个 gradle 版本?

标签: android android-gradle-plugin


【解决方案1】:

首先,你在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 Version = 21 编译它。它不能。您应该通过SDK Manager 更新BuildTools。 这是doc 关于最新的Build Tools 和很好的article 看看。那里的解释很好。

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

【讨论】:

  • 我没有在第一个 Manifest.xml 中声明任何内容,它只是错误消息指向的位置。我升级了buildToolsVersion,你的意思是:compileSdkVersion in build.gradle is lower than declared in Manifest.xml如何解决?
  • 您可以完全从Manifest 中删除&lt;uses-sdk&gt;,换句话说,它们在两个文件中必须相同。因此,更改清单中的值以将它们与gradle 匹配。如果您将build tools 更新为22.0.0 版本,那么您应该设置minSdkVersion = 15(与build.gradle 相同)并且compileSdkVersion 已经可以是22。 targetSdkVersion 可以是任何东西,但也可以相同(我的意思是从 15 到 22)。
  • 我解决了!查看我的开篇文章以了解我的解决方案。
  • 是的,没错,buildSdkTools 不能低于compileSdkVersion。很高兴它解决了。干杯:)
猜你喜欢
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
  • 2021-04-10
  • 1970-01-01
  • 1970-01-01
  • 2014-10-12
  • 2015-12-03
  • 2021-05-15
相关资源
最近更新 更多