清单合并失败

时间:2016-08-17 19:49:56

标签: android

所以很重要我从我的一个项目中得到了这个错误:

Error:Execution failed for task ':ListViewAnimations-core-slh:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 7 declared in library [android - AS:StickyListHeaders:unspecified] D:\Android\MDS\UPLOAD\android - AS\ListViewAnimations-core-slh\build\intermediates\exploded-aar\android - AS\StickyListHeaders\unspecified\AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="se.emilsjolander.stickylistheaders" to force usage

以下是相同的清单文件:

<manifest package="com.example.listviewanimations.slh" xmlns:android="http://schemas.android.com/apk/res/android">

    <application android:allowBackup="true">
    </application>

</manifest>

这是Gradle文件:

apply plugin: 'android-library'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':ListViewAnimations-core')
    compile project(':StickyListHeaders')
}

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

为什么会这样?我错过了什么? 非常感谢!

1 个答案:

答案 0 :(得分:1)

如果您不知道Android Studio如何为您的Android应用创建清单文件,则此错误消息可能有点误导。在这种情况下,重要的是要了解在app/build.gradle中设置了许多变量,这些变量在生成清单文件时使用。具体而言,错误消息引用minSdkVersion值。您应该打开app/build.gradle并找到包含此变量的行。然后将其值更改为7或更高。事实上,许多当前的应用程序使用的值至少为16。

修改build.gradle,如下所示:

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    defaultConfig { 
        minSdkVersion 7 // This can be any number greater than 7
    }
    // ...
}