[android] How do I use tools:overrideLibrary in a build.gradle file?

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?

This question is related to android gradle android-tv

The answer is


Use overrideLibrary when the minSdk is declared in build.gradle instead of in AndroidManifest.xml

If you are using Android Studio:

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


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'


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


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.


use this code in manifest.xml

<uses-sdk
android:minSdkVersion="16"
android:maxSdkVersion="17"
tools:overrideLibrary="x"/>

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


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.


<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.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-tv

How to install Android app on LG smart TV? How do I use tools:overrideLibrary in a build.gradle file?