Manifest merger failed : uses-sdk:minSdkVersion 14

2019-01-01 04:45发布

问题:

Since downloading the latest SDK and installing Android Studio, my project fails to build. I get the following message:

Error:Gradle: Execution failed for task \':SampleProject:processProdDebugManifest\'.
> Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version L declared in library com.android.support:support-v4:21.0.0-rc1

回答1:

Note: This has been updated to reflect the release of API 21, Lollipop. Be sure to download the latest SDK.

In one of my modules I had the following in build.gradle:

dependencies {
    compile \'com.android.support:support-v4:+\'
}

Changing this to

dependencies {
    // do not use dynamic updating.
    compile \'com.android.support:support-v4:21.0.0\' 
}

fixed the issue.

Make sure you\'re not doing a general inclusion of com.android.support:support-v4:+ or any other support libraries (v7, v13, appcompat, etc), anywhere in your project.

I\'d assume the problem is v4:+ picks up the release candidate (21.0.0-rc1) latest L release which obviously requires the L SDK.

Edit:

If you need to use the new views (CardView, RecyclerView, and Palette), the following should work:

compile \"com.android.support:cardview-v7:21.0.0\"
compile \"com.android.support:recyclerview-v7:21.0.0\"
compile \"com.android.support:palette-v7:21.0.0\"

(Credit to EddieRingle on /androiddev - http://www.reddit.com/r/androiddev/comments/297xli/howto_use_the_v21_support_libs_on_older_versions/)

Another Edit

Be sure to see @murtuza\'s answer below regarding appcompat-v7 and upvote if it helps!



回答2:

Also, in case you are importing the appcompat-v7 library make sure you tag a version number at the end of it like so:

compile \'com.android.support:support-v4:19.+\'
compile \'com.android.support:appcompat-v7:19.+\'

After only changing the support-v4 version, I still received the error:

Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version L declared in library com.android.support:support-v4:21.0.0-rc1

It was a bit confusing because it looks like v4 is still the problem, but, in fact, restricting the appcompat v7 version fixed the problem.



回答3:

Solution 1:

Change uses-sdk to <uses-sdk tools:node=\"replace\" /> and add xmlns:tools=\"http://schemas.android.com/tools\" in AndroidManifest.xml

 <?xml version=\"1.0\" encoding=\"utf-8\"?>
<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"
    xmlns:tools=\"http://schemas.android.com/tools\"
    package=\"com.demo.android\"
    android:versionCode=\"16\"
    android:versionName=\"3.3.1\">
    .
    .
    <uses-sdk tools:node=\"replace\" />
    .
    .
</manifest>

Make sure you use gradle 0.11 and above to use Manifest merger.

Solution 2:

  • Change compile \'com.android.support:support-v4:+\' to compile \'com.android.support:support-v4:20.+\' in build.gradle. This will prevent gradle from using v4:21.0.0 that requires version L.

  • However, if your any of your external dependencies uses the same. You will probably have to wait for them to update the same.

Solution 3:

  • Remove/Comment <version>21.0.0-rc1</version> in your file <android-sdk>/extras/android/m2repository/com/android/support-v4/maven-metadata.xml

  • Repeat the same for support-v7



回答4:

<uses-sdk tools:node=\"replace\" />

No longer works.

change uses-sdk to

<uses-sdk tools:overrideLibrary=\"com.packagename.of.libary.with.conflict\" />

and add
xmlns:tools=\"http://schemas.android.com/tools\" in the AndroidManifest.xml file



回答5:

The problem still arises with transitive dependencies. Gradle offers a way to force the usage of a specific version of a dependency.

For example you can add something like:

configurations.all {
    resolutionStrategy {
        force \'com.android.support:support-v4:20.+\'
        force \'com.android.support:appcompat-v7:20.+\'
    }
}

to your build.gradle.

If you want to learn more about gradle resolution strategies refer to this guide http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

I found this while reading the corresponding issue which I will link here



回答6:

In the build.gradle file, It was by default compile \'com.android.support:support-v4:+\' so when you build the gradle projecit would consider, com.android.support:support-v4:21.0.0-rc1 because of the recent L developer preview release.

Make changes in the following line and it will resolve the issue. Change

compile \'com.android.support:support-v4:+\' 

to

compile \'com.android.support:support-v4:20.+\'

Similarly when using v7-appcompat support library, make the change from

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

to

compile \'com.android.support:appcompat-v7:20.+\'.


回答7:

Adding to the correct answers above, the problem still might occur due to library nesting. In this case, try as the example below:

compile \'com.android.support:support-v4:20.+\'
compile (\'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+\') { // example
    exclude group: \'com.android.support\', module:\'support-v4\'
    exclude group: \'com.android.support\', module:\'appcompat-v7\'
}


回答8:

I also had the same issue and changing following helped me:

from:

dependencies {
    compile \'com.android.support:support-v4:+\'

to:

dependencies {
 compile \'com.android.support:support-v4:20.0.0\'
}


回答9:

for people building hybrid apps using cordova CLI, this command will help:

cordova build android -- --minSdkVersion=15

yes it uses double double dashes as you saw it.



回答10:

For people facing this issue in the Android Studio beta, the accepted answer didn\'t solve my problem. Importing a project downloaded from GitHub, I had the following in my build.gradle file of app giving an error in question:

 dependencies {
    compile \'com.android.support:support-v4:+\'
}

But in my external library folder I have this folder:

support-v4-21.0.0-rc1 //note the 21

I solved the above problem by changing the dependency to:

dependencies {
compile \'com.android.support:support-v4:20.+\' //20 used less than available strange but works
}

Note: you might also need to download api level lower than the currently available in Android Studio for some library and projects for this to work properly.



回答11:

I solved the problem by editing the line below in build.gradle and it works! :-)

adding version 20.+\'

From

 dependencies {
        compile \'com.android.support:appcompat-v7:+\'
    }

To

dependencies {
    compile \'com.android.support:appcompat-v7:20.+\'
}


回答12:

compile(\'com.android.support:support-v4:19.1.0\'){
    force = true
}

Helped me, taken from here



回答13:

You have to configure all the supports and appcompat libraries with version 19.+

If the recommendation of leave the support library with the 19.+ version doesn\'t works you can try the next tip in your AndroidManifest file.

First add this code:

xmlns:tools=\"http://schemas.android.com/tools\"

And then, at the application level (not inside application!)

<uses-sdk tools:node=\"replace\" />


回答14:

I make all of the solutions in here with no result, so i look in another place and i found a way to trick the IDE, so you have to put a line in the Mainfest to make the Gradle use a different one, the one that you put on build.gradle the line is:

<uses-sdk tools:node=\"replace\" />

just it, and it work.

I hope it helps.



回答15:

You need to remove from build.gradle compile \'com.android.support:support-v13:+\'



回答16:

Here\'s the new bug filed for this btw https://code.google.com/p/android/issues/detail?id=72430

Assuming you are using the Support Repository, the workaround is to comment or remove the line

21.0.0-rc1 in the local Maven repo listing file at /extras/android/m2repository/com/android/support-v4/maven-metadata.xml



回答17:

Don\'t forget, you should edit build.gradle in \'app\' subfolder of your project, not in project\'s folder. I\'ve lost a working day trying to solve a problem with version \"L\".



回答18:

Try deleting the build folder(s) in your project and resync your gradle project to rebuild it. Also, like others have said in this post - instead of doing something like this:

compile \'com.android.support:support-v4:19.+\'

do this:

compile \'com.android.support:support-v4:19.1.0\'


回答19:

Thank you @Murtuza. Your answer helped me to solve my problem but in my case

compile \'com.android.support:support-v13:19.+ also, along with

compile \'com.android.support:support-v4:19.+\' compile \'com.android.support:appcompat-v7:19.+\'

from compile \'com.android.support:support-v4:+\' compile \'com.android.support:support-v7:+\' compile \'com.android.support:support-v13:+\' Hope this might help some one



回答20:

I have some projects where I prefer to target L.MR1(SDKv22) and some projects where I prefer KK(SDKv19). Your result may be different, but this worked for me.

// Targeting L.MR1 (Android 5.1), SDK 22
android {
    compileSdkVersion 22
    buildToolsVersion \"22\"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 22
    }
}

dependencies {
    compile fileTree(dir: \'libs\', include: [\'*.jar\'])

    // google support libraries (22)
    compile \'com.android.support:support-v4:22.0.0\'
    compile \'com.android.support:appcompat-v7:22.0.0\'
    compile \'com.android.support:cardview-v7:21.0.3\'
    compile \'com.android.support:recyclerview-v7:21.0.3\'
}



// Targeting KK (Android 4.4.x), SDK 19
android {
    compileSdkVersion 19
    buildToolsVersion \"19.1\"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }
}

dependencies {
    compile fileTree(dir: \'libs\', include: [\'*.jar\'])

    // google libraries (19)
    compile \'com.android.support:support-v4:19.1+\'
    compile \'com.android.support:appcompat-v7:19.1+\'
    compile \'com.android.support:cardview-v7:+\'
    compile \'com.android.support:recyclerview-v7:+\'
}


回答21:

In Android Studio 1.1.0: File - Project Structure - Tab Flavors - Select Min SDK Version which is higher than in Manifest



回答22:

I have the second solution:

  1. unzip https://dl.dropboxusercontent.com/u/16403954/android-21.zip to sdk\\platforms\\
  2. change build.gradle like

    compileSdkVersion 21
    buildToolsVersion \"20.0.0\"
    
    defaultConfig {
        applicationId \"package.name\"
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 1
        versionName \"1.0\"
    }
    
  3. add

    <uses-sdk tools:node=\"replace\" /> 
    

    in Manifest with xmlns:tools=\"schemas.android.com/tools\";

  4. Go to sdk\\extras\\android\\m2repository\\com\\android\\support\\support-v4\\21.0.0-rc1\\

unpack support-v4-21.0.0-rc1.aar and edit AndroidManifest.xml like

from

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

to

<uses-sdk
        android:minSdkVersion=\"4\"
        android:targetSdkVersion=\"21\" />

P.S. You can do this with all support libraries that need.



回答23:

The only thing that worked for me is this:

In project.properties, I changed:

cordova.system.library.1=com.android.support:support-v4:+ to cordova.system.library.1=com.android.support:support-v4:20.+



回答24:

For me the issue like this is solved by changing the

minSdkVersion 14

In the build.gladdle file and use the one that is specified in the error message

but the issue was

Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 15 declared in library

So I changed from 14 to 15 in the build.gladdle file and it works

give it a try.