How do I use tools:overrideLibrary in a build.gradle file?
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
How to use tools:overrideLibrary with multiple libraries
I have found out that the solution is to create a second AndroidManifest.xml, just for the tests. It has to be saved into the tests directory and needs to contain only the overrideLibrary statement:
<?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="${applicationId}">
<uses-sdk tools:overrideLibrary="android.app, android.support.test, android.support.test.rule, android.support.test.espresso, android.support.test.espresso.idling, android.support.test.uiautomator.v18"/>
</manifest>
If you are using a different directory for your tasks, you can specify it this way in your gradle file:
androidTest.setRoot('src_test_uiautomator')
The AndroidManifest.xml file has to be in the root of that directory, the test sources in the "java" subdirectory.
Understanding tools:overrideLibrary on Android
YEs, if the library call an API 15 function and the device is only API 14, it will crash. If the device is API15 or higher it will still work.
I wouldn't worry about it in this case though. 14 was Anroid 3.x. There were only a tiny number of 3.x devices made- Android tablets didn't take off until after 4.0 was released. The percentage of 3.x models in use is less than .1% of all devices. If they don't work, is it really worth the time and effort to support them? Honestly I'd just raise your minsdk to 15 or higher. (raising it to 19 only eliminates 10% of the worldwide market, which would heavily skew to low income countries in Asia, Africa, and South America. If your major targets are the US and EU, it may not be worth the cost of supporting that).
Force tools:overrideLibrary Android
You are using a library that its minsdkversion is below your project's minsdkversion.
Just change your minsdkversion in your build.gradle file of your app to 15 and that will be ok ;)
There is another way which is not stable. Just force it to use by adding one line of code to your application manifest. See this link:
How do I use tools:overrideLibrary in a build.gradle file?
Manifest merger failed, use tools:overrideLibrary
You are using a library ("com.android.support:leanback-v17:23.2.1") which has a minimum sdk version of 17 so you can not build your app for sdk version 17. If you don't need the library you should delete the line: compile 'com.android.support:leanback-v7:23.2.1'
from your Module gradle file. If you need it you will nedd to change the minimum sdk version of your app to version 17. More information on this topic on: http://developer.android.com/reference/android/support/v17/leanback/package-summary.html
What this mean uses-sdk tools:overrideLibrary=com.google.android.gms / in Android
according to http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
tools:overrideLibrary marker
A special marker that can only be used with uses-sdk declaration to override importing a library which minimum SDK version is more recent than that application's minimum SDK version.
Without such a marker, the manifest merger will fail. The marker will allow users to select which libraries can be imported ignoring the minimum SDK version.
and according to http://www.reddit.com/r/androiddev/comments/297xli/howto_use_the_v21_support_libs_on_older_ve
Version 0.11 of the Android Gradle Plugin turned on a new Manifest Merger by default, and it allows us to do some nifty stuff (read more about it here). In the manifest above, I'd included a uses-sdk node that simply specifies a tools:node attribute. This specific configuration tells the manifest processor to replace any attributes from uses-sdk nodes in lower-priority manifests (such as library manifests) with the attributes in the uses-sdk node with the tools:node="replace" attribute. Since Gradle also inserts minSdkVersion and targetSdkVersion from your build.gradle into this uses-sdk node, that's all we really need to add.
Now you should be able to run your application on any device supported by your minSdkVersion, while taking advantage of the neat new views and utilities in the support lib!
Related Topics
How to Use Radiogroup in Listview Custom Adapter
How to Get Android Device Screen Size
Trying to Get the Display Size of an Image in an Imageview
Android - Extracting Cookies After Login in Webview
How to Animate a View with Translate Animation in Android
How to Move the Layout Up When the Soft Keyboard Is Shown Android
Android Recyclerview:Notifydatasetchanged() Illegalstateexception
Android - Get Time of Chronometer Widget
Android - Configure Spinner to Use Array
How to Draw a Route, Along an Existing Road, Between Two Points
How to Use Getsharedpreferences in Android
How to Resolve "Waiting for Debugger" Message
Eclipse/Android:"Errors Running Builder 'Android Pre Compiler' on Project..."
Error :: Duplicate Files During Packaging of APK
Android Background Image Memory Usage
How to Debug APK Signed for Release
How to Add Button Tint Programmatically
Android Deep Linking: Use the Same Link for the App and the Play Store