Android Support Package / Compatibility Library - use v4 or v13?
Asked Answered
N

6

31

I've just read this description of the Android Support Package / Compatibility Library...

http://developer.android.com/sdk/compatibility-library.html

... and it's left me a little confused! It says that the v13 library is a superset of v4 but I thought it was the other way around?

Getting practical: If I want to use the compatibility library such that my app builds and works fine for phones running Android 2.2 (API 8) through to 4.0 (API 14) and beyond, will v4 suffice for me?

Nucleotide answered 29/3, 2012 at 13:31 Comment(0)
W
35

To target API 8 (v2.2) you should use the v4 version.

Large sections of the v13 will work, but if you use any of the features in it that rely on the platform 13 APIs, your app will blow up on older devices.

Unless there's a particularly compelling reason to need v13, I'd suggest going straight for v4.

Wield answered 29/3, 2012 at 13:41 Comment(6)
To clarify: I'm specifying 'targetSdkVersion' as "14" and 'minSdkVersion' as "8" in my manifest. So v4 is still the one I want right?Nucleotide
If you use the v13, and you use a feature in it that relies on a platform 13 API, your app will blow up. Just because it compiles, doesn't mean it'll work on all devices.Wield
I still does not understand if v13 requires 13+ devices why is it a superset of v4...Koss
It's the same as saying v4 is a subset of v13. All of the APIs in v4 are included in v13, and the extra APIs in v13 that are not from v4 require 13+.Defrayal
Thanks @ChristopherPerry I was mistakenly adding both the v4 and v13 support libraries and your comment solved my problem. If my minSdkVersion is greater than 13 I only need v13 not both.Jude
I checked the source of v13, it only adds 4 more classes.Electrokinetic
A
9

The Answer is correct but is also slightly confusing! Currently there are 3 support jars: V4, V7 and V13. Unfortunately V7 is specifically for gridlayout only and is therefore NOT a superset.

We are interested in only one jar from the support library [unless we also want gridlayout (I don't know what it is!)]. Therefore we are looking at our android:minSdkVersion="8" and checking it against the jars. So we want V4.

V13 is only a superset in the sense that it duplicates the V4 methods, NOT the code. I.e. the use of V13 would be incorrect in this example.

Ammunition answered 7/5, 2013 at 16:45 Comment(0)
S
5

I don't think we should use superset(or subset) to describe these three libraries(v4, v7, v13) though the simplest meaning seems backward-compatible version 4, 7 and 13.

Google added Fragment in v4 first,then update it when every new version was published.That means unless your app only support the newest version (which strongly not recommended), we need support-v4 almost anytime.Suppose your minsdk is 14 which has fragment already, but 'embedded fragment' only support after 17,so we still need v4 and use v4 fragment in that situation.

This year(2013) google published v7,and added appcompat-library in it.That means besides third support Actionbar(ActionbarSherlock) before 11, offical support maybe a better One?? Then I believe we'll have every actionbar feature update when every new version publish in future in v7.

We still need minsdk=XX (between 7 and 10) today(Nov.24,2013).We should add support-v4 for fragment and support-v7 for actionBar both for best practice.

Scribble answered 24/11, 2013 at 11:29 Comment(1)
your answer explains pretty nicely that there is no subset superset relation between these libraries which most of the people believe.Titanite
E
1

I checked the source code of v13, it adds only 4 more classes.

  • FragmentCompat
  • FragmentPagerAdapter
  • FragmentStatePagerAdapter
  • FragmentTabHost

FragmentCompat adds 2 static util methods which are included in v4 Fragment already.

FragmentPagerAdapter, FragmentStatePagerAdapter and FragmentTabHost, all these 3 classes have corresponding same name classes in v4, and have the same behavior.

The extra APIs provided in v13 are not necessary.

So by adding v4, you can support more platforms than v13, with same behavior with v13, so why not just use v4?

So I could not see any neccessarity for v13. Am I right?

Electrokinetic answered 16/9, 2014 at 3:58 Comment(0)
H
0

v13 just have functions about Fragment. mostly if your minVersion is above 13 and not used functions like : FragmentPagerAdapter,FragmentStatePagerAdapter,FragmentTabHost,and nested fragments; you do not need support v13.

so "v4 is a subset of v13" is incorrect!

Helbonna answered 12/5, 2014 at 1:28 Comment(0)
F
0

A little late but please have a good look at the picture below. In the JAR file android-support-v13.jar, there are 3 packages:

  • annotation
  • v4
  • v13

Meaning we just need to add this one jar, and we would have support for both v4 and v13. Since v7 is NOT in the compilation, we would need to add that JAR on our own.

enter image description here

Fusilier answered 23/5, 2015 at 23:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.