Aung Pyae
Aung Pyae

Reputation: 1610

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

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.

Upvotes: 3

Views: 5038

Answers (3)

MinceMan
MinceMan

Reputation: 7592

The best solution is RecyclerViewLib. The support library has been pulled into a repo and published on maven central. It'll be safe even after L is released as all L dependent code has been removed. The author explains it here in his blog post.

To use it in your project just add the following line in your build.gradle dependencies:

compile 'com.twotoasters.RecyclerViewLib:library:1.0.+@aar'

Good luck!

Upvotes: 1

Aung Pyae
Aung Pyae

Reputation: 1610

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.

Upvotes: 15

Alexander Mikhaylov
Alexander Mikhaylov

Reputation: 1800

No you must set targetSdkVersion above 7. You can use android support library v7 with project that support android above 7 api level. And one more. Android L has api level 'android-L', not 20. Under the hood it has api level 21 (20 is 4.4W, KitKat for wearables).

Upvotes: 0

Related Questions