362

I'm using the leanback libraries, which require Android 17 or later. However my app supports a minSDK of 16, so I get a build error from gradle saying

Error:Execution failed for task ':Tasks:processPhoneDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library /Users/mike/Projects/android-for-dummies-v3/Tasks/build/intermediates/exploded-aar/com.android.support/leanback-v17/21.0.2/AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="android.support.v17.leanback" to force usage

When I look at the build tools documentation, I see how to add the overrideLibrary marker to my manifest, but the problem is that I'm declaring my minSdk in my gradle file instead of in my manifest.

How do I use overrideLibrary when the minSdk is declared in build.gradle instead of in AndroidManifest.xml?

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
emmby
  • 99,783
  • 65
  • 191
  • 249
  • Dont do this. Instead update minsdkversion in the build.gradle – Dr Deo Apr 04 '18 at 08:04
  • 7
    There are legitimate reasons to do this, such as conditionally use a library by testing API level before using it. – Guillaume Perrot Jan 15 '19 at 01:53
  • For those who don't know what `overrideLibrary` does, "When the lower-priority manifest has a minSdkVersion value that's higher, an error occurs unless you apply the overrideLibrary merge rule." [source](https://developer.android.com/studio/build/manifest-merge.html#merge_conflict_heuristics). Effective, this overrideLibrary simply removes the warning, it does not change anything else. – Ben Butterworth Aug 29 '20 at 08:28

9 Answers9

684

Open Android Studio -> Open Manifest File

add <uses-sdk tools:overrideLibrary="android.support.v17.leanback"/> don't forget to include xmlns:tools="http://schemas.android.com/tools" too, before the <application> tag

enter image description here

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
xDragonZ
  • 12,502
  • 6
  • 37
  • 52
  • in my case `tools:overrideLibrary="info.hoang8f.fbutton"` – shareef Dec 12 '15 at 11:40
  • 18
    Watch out for included libraries that contain ``. Those will cause your `tools:overrideLibrary` attribute to be ignored. See http://stackoverflow.com/questions/31062893/android-gradle-manifest-merger-failed – Theo Aug 05 '16 at 17:37
  • 1
    My problem still exists after adding tools:overrideLibray="ca.barrenechea.widget.recyclerview.decoration". It was working but suddenly stopped working today after creating a new activity. – arjunkn Feb 08 '17 at 06:53
  • @arjunkn : add , If its not working check if your tools namespace is correct or not the correct namespace is xmlns:tools="http://schemas.android.com/tools" – NIPHIN Apr 04 '18 at 10:20
  • 2
    what if i want more than overridelibrary – Mostafa Anssary Mar 08 '20 at 17:22
224

it doesn't matter that you declare your minSdk in build.gradle. You have to copy overrideLibrary in your AndroidManifest.xml, as documented here.

<manifest 
    ... >
<uses-sdk tools:overrideLibrary="com.example.lib1, com.example.lib2"/>
    ...
</manifest>

The system automatically ignores the sdkVersion declared in AndroidManifest.xml.

I hope this solve your problem.

olfek
  • 3,210
  • 4
  • 33
  • 49
icastell
  • 3,495
  • 1
  • 19
  • 27
  • 1
    Do you have to specify any versions in the uses-sdk? It seems confusing to specify versions in AndroidManifest that are just going to be ignored – emmby Dec 01 '14 at 16:54
  • 1
    You are right. Is not necessary, anyways if you set it in the AndroidManifest gradle will ignore it at compilation time. – icastell Dec 02 '14 at 08:44
  • 21
    +1 for display two libs in example. You can't use two seperate uses-sdk tag. so if you want to override two or more you can put comma in-between. Thanks!! – Hitesh Chavda Sep 03 '15 at 12:28
  • 2
    but this didn't work for me to use two libraries separated by comma, any problem with my library? – Zia Ur Rahman Sep 29 '16 at 17:26
20
<manifest xmlns:tools="http://schemas.android.com/tools" ... >
  <uses-sdk tools:overrideLibrary="nl.innovalor.ocr, nl.innovalor.corelib" />

I was facing the issue of conflict between different min sdk versions. So this solution worked for me.

LarsH
  • 27,481
  • 8
  • 94
  • 152
Kuldeep Saxena
  • 1,803
  • 1
  • 14
  • 17
3

just changed only android:minSdkVersion="16" and it's work perfect C:\MyApp\platforms\android\CordovaLib\AndroidManifest.xml

1

use this code in manifest.xml

<uses-sdk
android:minSdkVersion="16"
android:maxSdkVersion="17"
tools:overrideLibrary="x"/>
ali bagheri
  • 139
  • 2
  • 5
0

I just changed minSdkVersion="7" in C:\MyApp\platforms\android\CordovaLib\AndroidManifest.xml and it worked.

Steps:

  1. Path: C:\MyApp\platforms\android\CordovaLib\AndroidManifest.xml
  2. Value: <uses-sdk android:minSdkVersion="7"/>
  3. Ran command in new cmd prompt:

    C:\MyApp>phonegap build android --debug [phonegap] executing 'cordova build android --debug'... [phonegap] completed 'cordova build android --debug'

Smar
  • 8,109
  • 3
  • 36
  • 48
  • 1
    This doesn't answer the question, which is how to use `overrideLibrary` when the minSdk is declared in build.gradle. – LarsH Jul 11 '18 at 13:45
0

As soulution for all libraries we can match sdk version of them so no unexpected event may happen

subprojects { 
afterEvaluate {project -> 
    if (project.hasProperty("android")) { 
        android { 
            compileSdkVersion 28 
            buildToolsVersion '28.0.3'
            defaultConfig {
                //It's kinda tricking android studio but anyway it works
                minSdkVersion 17
            }
        } 
    } 
    if (project.hasProperty("dependencies")) {
        dependencies {
            implementation 'com.android.support:support-core-utils:28.0.0'
            implementation 'com.android.support:appcompat-v7:28.0.0'
            implementation 'com.google.android.gms:play-services-base:16.1.0'
        }
    }
} 
}

Remove libraries that you do not use in your project (gms) and make sure that sdk version matches your app level gradle data

Mohammad f
  • 961
  • 10
  • 11
0

That work for me

<uses-sdk 
    android:minSdkVersion="16"
    android:maxSdkVersion="17"
    tools:overrideLibrary="pl.droidsonroids.gif" />
      


   
-1

As library requires minSdkVersion 17 then you can change the same in build.gradle(Module:Application) file:

defaultConfig {
        minSdkVersion 17 
        targetSdkVersion 25
}

and after that building the project should not throw any build error.

goto
  • 7,908
  • 10
  • 48
  • 58
Arpit Namdev
  • 63
  • 1
  • 1
  • 4
    While this would work, it doesn't actually answer the question. OP asks how overrideLibrary is used. And there are specific cases where you'd want to override it instead of comply (as it's fine to override it) – Zoe Feb 23 '18 at 16:20