I've been developing for Android for a few months now, and this question arises again and again: what is the motivation behind addition of completely new features (APIs) to support libraries without them being available in the standard SDK?
Example:
FragmentTabHost API is available only through android.support.v4.app.FragmentTabHost
. It is fine most of the time, but if you want to use fragments nesting and PreferenceFragment together, you're dead in the waters - nesting requires you to switch to android.support.v4.app.Fragment
(for supporting below 4.2), but there is no implementation of PreferenceFragment in this support lib. As a consequence you either implement custom workarounds, or use third party libraries that have already implemented them (see this question)
Edit: as pointed out by @eugen in his answer, I myself referenced FragmentTabHost from support-v13, which supports native Fragments. However, this information does not change the overall question. In fact, if I would've used this API with fragments nesting, my app wouldn't run on ~30% of devices today (native fragments support nesting from 4.2 onwards).
Example:
Another issue that I encountered today (and wasted too much time on) is with ActionBarDrawerToggle available through android.support.v7.app.ActionBarDrawerToggle
. I wanted to use this functionality, therefore I added the entire com.android.support:appcompat-v7:21.0.+
to project's dependencies. I guessed that this will do, but I was wrong - my app did not compile (missing resources referenced by the support library). After trying few tricks from the web, I found this question which finally provided the solution. In short: v7 support library has dependency on SDK, therefore I had to define compileSdkVersion 21
.
Consequences:
Now, I tell myself: FragmentTabHost haven't been added to any SDK version yet, which implies that even 4-5 years from now developers will continue to use support-v4 lib for providing this functionality (because even if this API is added today, it will take years before you could safely assume that all target devices support it natively), right? The same argument applies to android.support.v4.widget.DrawerLayout
and other APIs present only in support libraries.
If developers bound to use support libraries for years, this also imply that they are bound to experience the above inconsistency/dependency issues long after these issues could have already been resolved, right?
Question:
Why would Google want to keep these libraries forever? Won't it be better for everybody if all the new APIs were added to SDK in parallel to compatibility libs, such that compatibility libraries could age and "retire" at some point?
Edit: following @eugen's answer I'm now puzzled even more - some APIs "evolve" with newer support libs, but do not make it into main SDK (like FragmentTabHost, which evolved from support-v4 to support-v7). What is the reason for not adding them to SDK?
RecyclerView
must be accessed solely from a support library. I believe other than the reasons you've already listed, that it may be a way to try to keep the SDK minimal if google can put "extra, non-standard" features in a different library.FragmentTabHost
did not evolve from anything. There are two separate versions.support-v4
which handles support fragments andsupport-v13
which handles native fragments. ||| Using support fragments is better because they get fixed quicker. Libraries get fixed often. To fix anything native, Google would have to put out a new version of Android and the fix would be exclusive to that new version. Everybody else would have to use the support library.FragmentTabHost
for nativeFragment
would've been added to the main SDK instead ofsupport-v13
, then, of course, some bugs would've been discovered (as with any new API). But these bugs would've been resolved in 1-3 SDK releases, and, starting with Android 5.x (or 6.x, whatever), this API would become stable. Then, few years from that point, any developer wishing to use this API could do this without any support library whatsoever. The question is why not add new APIs to SDK at some point?ViewPager
to the support libraries was a mistake. This widget is too ubiquitous not to standardize. Also it is one of the few real arguments in favor of using a fragment-based design on a mobile UI, and if fragments are in the framework then so should this. Similarly, ifRecyclerView
was indeed designed to eventually effectively replaceListView
, then it should also be in the framework.ActionBarSherlock
), which work well, to be either "promoted" by Google, or maintained by it. While their desire is totally legit, and the reasoning by @RomainGuy about keeping SDK small and not adding components which might "fall out of fashion", this still doesn't explain thy add them to Support Libs... Why not having separate libs forDrawerLayout
andViewPager
?