Can I use Widgets from support library of Android L Preview in current Android Version?

android, android-5.0-lollipop, android-studio, gradle

Solution

I just found the solution. The reason why I can't build the App with RecyclerView & CardView while the targetSdkVersion and minSdkVersion is not "Android-L" is because internally Google designed to treat the preview version of OS differently comparing with original releases.

When I compile the App which contains the components from Android-L, the build tools locked minSdkVersion and targetSdkVersion to same level. The new supports libraries (RecyclerView, CardView, Palette, etc) are also locked into the L API level.

This behaviour is only happening on this Android-L preview release.

The fix for it is to put the following in AndroidManifest.xml. I didn't need to change anything on my gradle script.

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

Since version 0.11 of Android Gradle Plugin, it turned on a new Manifest Merger by default. It allows us to do some niffy stuffs. This specific configuration tells the manifest processor to replace any attributes from uses-sdk nodes in lower-priority manifest (such as library manifest in this case) with this attributes.

Since Gradle also inserts minSdkVersion and targetSdkVersion from your build.gradle into this uses-sdk node, that's all we really need to add.

Check here for more information related to this issue. Check here for the info related to Manifest Merger.

Problem

I am trying to use RecyclerView & CardView in existing Android version. They said it is in support library. So, I should be able to use those with put "compileSdkVersion" to "Android-L". Right ? I am trying to use those widgets without Android L Preview device or emulator.I have checked other questions on this matter. But, seems they all are trying Android-L with Android-L version. Here is my dependencies. compile 'com.android.support:support-v4:13.0.+' compile 'com.android.support:recyclerview-v7:+' Here is my target config minSdkVersion 15 targetSdkVersion 20 Thanks in advance for any idea.

Original source