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

2,610 views
Skip to first unread message

Mateusz Grzechociński

unread,
May 1, 2014, 9:21:42 AM5/1/14
to adt...@googlegroups.com
Hi,

I've just upgraded to Gradle 1.12 and Android gradle plugin v1.10. Just out of curiosity, I also switched to new android manifest merger by specifying:

android{
   useOldManifestMerger false
}

After switch, I encountered several problems. All but one were very clear for me and I fixed them in a couple of minutes - duplicated permissions, missing package names etc. Btw, I love the ${packageName} expression to be used in intent filters etc. 

The last problem I have is with merging android:minSdkVersion attribute between my app buildTypes/flavors/dependencies.

My project structure is just a standard:

- root
-- app (app is build to APK and has dependency to app compat library)

My app module has several build types and flavours. One of the build type and flavour configuration is Mo (flavour) Debug (buildType). In both debug/ and mo/ folders I have a manifest files which, in debug/ adds some additional activities to main manifest (DeveloperOptionsActivity etc) and in mo/ adds some additional permissions for GCM for different environment. 

In build.gradle of my app module I have:

 defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        [...]
 }

  buildTypes {
      debug {
            debuggable true
            packageNameSuffix ".debug"
            runProguard false
      }
      ...
  }

   productFlavors {
        mo {
        }
        ...
  }

Neither my main/ nor debug/ nor /mo  AndroidManifest.xml specify <users-sdk /> since when they do, lint says:

So I removed it from all main/ and debug/ and mo/ AndroidManifest.xml.

Once I did it, I see:

app:processMoDebugManifest
/Users/mateuszgrzechocinski/[...]/app/src/debug/AndroidManifest.xml:0:0 Error:
uses-sdk:minSdkVersion 1 cannot be smaller than version 7 declared in library com.android.support:appcompat-v7:19.0.1
:app:processMoDebugManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processMoDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 7 declared in library com.android.support:appcompat-v7:19.0.1
 
The only way to get rid of this issue it to put <uses-sdk androidMinSdkVersion="9" /> in my debug/AndroidManifest.xml. That's not what I want, since I'd like one, and only one place for minSdkVersion to be set for my whole application and it's android{ minSdkVersion 9 } in my build.gradle. Lint thinks the same, I guess.

What's more interesting, putting <uses-sdk androidMinSdkVersion="9" />  in my main/ AndroidManifest.xml file doesn't change anything. Seems like every AndroidManifest.xml variant have to have it's owns <uses-sdk />, or am I missing something?

Thanks in advance and thank you Xavier and your team for a tremendous work!

Matthew


Xavier Ducrohet

unread,
May 1, 2014, 11:54:12 AM5/1/14
to adt...@googlegroups.com
It looks like the minSdkVersion check is not taking into account the version injected from the build.gradle and instead relies on the one present in the manifest file. We are investigating.


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Mateusz Grzechociński

unread,
May 1, 2014, 6:10:03 PM5/1/14
to adt...@googlegroups.com
W dniu czwartek, 1 maja 2014 17:54:12 UTC+2 użytkownik Xavier Ducrohet napisał:
It looks like the minSdkVersion check is not taking into account the version injected from the build.gradle and instead relies on the one present in the manifest file. We are investigating.

Exactly. Waiting for any news. Let me know if you need any additional testing.

Matthew

Mateusz Grzechociński

unread,
May 1, 2014, 6:59:19 PM5/1/14
to adt...@googlegroups.com
Oh I forgot to add, that in my opinion it also ignores the <uses-sdk /> tag from main/AndroidManifest.xml.

In other words, when I have a library project which specifies <uses-sdk /> in it's AndroidManifest.xml file and main project which has buildType without it's specific AndroidManifest.xml (so default from main/ should be used), it also raises the same exception - <uses-sdk /> is treated as non existing (with default minSdkVersion = 1) and conflicts with this one from library's AndroidManifest.xml

M.

Jerome Dochez

unread,
May 1, 2014, 11:40:28 PM5/1/14
to adt...@googlegroups.com
I just merged a change that should take care of the issue. 

Thanks for the great report.
jerome

Diego Costantini

unread,
May 2, 2014, 5:38:00 AM5/2/14
to adt...@googlegroups.com
Same here :)
Once I worked around it I am getting a BUILD SUCCESS but with a red error without explanation (I expected the NPE you mentioned in your other thread).

I am dealing with GCM as well, I'll report errors or success :)

Mateusz Grzechociński

unread,
May 4, 2014, 9:29:41 AM5/4/14
to adt...@googlegroups.com
Is this merged changed available in 0.10.1? After upgrading, I can remove <uses-sdk> from my variant folder (either flavor or buildType) and my AndroidManifest.xml is successfully merged with main/. 

Unfortunately it still seems like merge tool doesn't respect minSdkVersion and targetSdkVersion from build.gradle. Once I remove <uses-sdk /> from my main/AndroidManifest.xml, and have build.gradle and exactly one place in my project where minSdkVersion is specified, I get:

Caused by: java.lang.IndexOutOfBoundsException: Illegal start index
at com.android.utils.PositionXmlParser.getPosition(PositionXmlParser.java:354)
at com.android.utils.PositionXmlParser.getPosition(PositionXmlParser.java:301)
at com.android.manifmerger.XmlDocument.getNodePosition(XmlDocument.java:157)
at com.android.manifmerger.XmlAttribute.getPosition(XmlAttribute.java:101)
at com.android.manifmerger.XmlNode.getLine(XmlNode.java:126)
at com.android.manifmerger.XmlAttribute.addMessage(XmlAttribute.java:320)
at com.android.manifmerger.XmlAttribute.addConflictingValueMessage(XmlAttribute

M.
Reply all
Reply to author
Forward
0 new messages