Understanding Android support libraries - android

I am currently reading up on the Android Support Libraries (I am aware of Jetpack/AndroisX, but can't use them yet).
I understand that v7 depends on v4, so with adding v7 I get v4 and what comes with v7. What I don't understand are the other v<number> like v8, v13. Do they extend v7? In general, if I start a new application with Android Support Libraries, would I use the highest v<number> or still v7?

You should think in v4, v7, v13 as the name of the library and not like an actual "version". In a certain way, they are just the name of the library.
Each Android Support Library comes with its own set of sub-libraries. Those sub-libraries can be found in one library (v7, for example) and therefore, you can't just use the highest number (if you try to use v13 you get an error).
CardView for example. You add it to your project with com.android.support:cardview-v7:28.0.0. It is only found in the v7 library. If you try to import via com.android.support:cardview-v13:28.0.0, you will get an error.
Some classes can be found in more than one library (e.g. Fragments). They can be found in v4 and also on v13. However, each of those classes have a different implementation. So, you should use v4 or v13 according to your project/necessity. You don't need to simply use the highest number because they are just names... not an actual version.
If you simple use v13, for example, you won't get v7 sub-libraries because the v13 library does not depends of the v7 library.

Related

Android studio: how to properly use the support library AppCompat?

I know there are many versions such as v4, v7, v8, v13, v14, v17, etc and they aren't in order of upgrades. What I don't understand is the meaning of this checkbox in Android Studio when you create a new project and choose an empty activity
Backwards compatibility (AppCompat)
The description says
if false, this activity will be Activity instead of AppCompatActivity
It's a bit foggy to me, then I checked the library and I found out that it was android.support.v7.app.AppCompatActivity
The descriptions says that
v7 Support Libraries
There are several libraries designed to be used with Android 2.3 (API level 9) and higher.
Again I don't understand whether I have to use it or not, depending on different cases. If I set the maximum target API, what is the necessary minSdk to not use it?
It is not simple to answer your question.
The Support Libraries provide a wide range of classes for building apps, from fundamental app components, to user interface widgets, to media handling, to TV app components.
Many of the classes are backward compatible implementations, but some of them are new features in their own right.
It is very important this step. Not all support libraries are used to support backward implementation.
For example in your application you will need to use some components like:
RecyclerView
CardView
ViewPager
Design Library
.....
In particular the design support library has a dependency with the appcompat library.
It means that you can't avoid the use of the support libraries only using a minSdk. Or in other words you have to use them always.
Here more info about the support libraries.
Please note that, when you opt out support libraries, you can not get benefit of the powerful RecyeclerView, CardView, DesignSupportLib etc. Because these libs are dependent on appCompat
what version should we use in order to avoid the support library?
You can use any version as min sdk version. It does not matter. Support lib is included in every project by default by android studio, you have to remove it manually.
How to create new project without support library?
While creating a new project,set min sdk version as 14 (just for example), don't add
any activities during the wizard dialog. Just create a project with
no activities. Then after you can add code as you wish
You can remove the support library , removing the dependency from your build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:appcompat-v7:25.2.0'
}
Replace your theme parent in styles.xml into a non AppCompat version like Holo.Light

Android Support Libraries

Sorry might be silly question here. First of all i am a bit new to android.There is always confusion in my mind when it comes to Support Library. What killing me most is if I have multiple libraries in my dependencies and each use different Support Library versions. One use V4 and other use "v7" with different build version. Project it's self use another version. Wouldn't be any conflict or duplicate entries cuz each one has separate versions. :-)
Edited
Library A ( v7:22.1.1 )
Library B ( v4:19.1.0 )
Library C ( v4:18.0.0 )
app ( v4:18.0.0 )
As my expectation , there should be conflict but i can run project without any flaw which make me big confusion.
Edited
It is said that v7 include v4 so i removed support library in all sub modules and put v7 in app module. After i had changed ,i've errors and can't even build ..
Would be very appreciate for explanation cuz mostly all beginner might have those confusion
Actually v7 includes the v4 support library. There wont be any conflict and duplicate entries between them.
v4 Support Library
This library is designed to be used with Android 1.6 (API level 4) and higher. It includes the largest set of APIs compared to the other libraries, including support for application components, user interface features, accessibility, data handling, network connectivity, and programming utilities.
v7 Support Libraries
It contains several libraries designed to be used with Android 2.1 (API level 7) and higher. These libraries provide specific feature sets and can be included in your application independently from each other and added extra features.
v7 include v4 support library so if you are importing v7 than no need to add v4
You can check in v7 libs folder it includes v4 library
Now if you have multiple library(module) project which has some hierarchy than attach library to the main parent library and add that parent library to your sub library project or main project
Library_A (Required v4 or v7's some of the classes)
Library_A1 (Required v4 or v7's some of the classes)
Main_Porject(Final one)
Add Support v7 to Library_A only
Add Library_A to Library_A1 as a module
No need to add v7 to both Library_A & Library_A1 it can cause conflicts
Attach only Library_A1 to Main_Project as a Module.
And Using multiple v7 library with different version will cause problem.

Eclipse Android missing getSupportFragmentManager and getChildFragmentManager

Hi I tried using the android supported lib v4 as well as v13 instead of android app lib but eclipse still cannot recognize the getSupportedFragmentManager and getChildFragmentManager functions. Are there any steps I need to take in order fro eclipse to recognize both functions?
Currently using Eclipse luna with latest android sdk, targeting api 17 platform.
I need either function to see why the app crashes with no view found for id ?? when using viewpager inside dialogfragment.
Thanks in Advance.
I found the reason why eclipse cant recognize both functions and that is because while getSupportFragmentManager is available in supported lib v13 but both function are only available in support lib v4 which is weird considering v13 is higher and v4 is included. perhaps they removed getChildFragmentManager function in v13 for some reason. Discovered when using the software provided here jd.benow.ca to search for the function on which class they reside and viola, v13 actually don't have getChildFragmentManager in any of the classes available and it's only existed in v4, so for now, if getChildFragmentManager is needed just use support lib v4 for now or find a way to use both support lib v4 and 13. happy programming using support lib v4 and v13 guys.

Why does the method count goes up not down when switching from android-support-v4 to v13

When switching from support library v4 to v13 I expected the method count number to go down because now all the methods which are in the SDK version 13+ don't have to be in the support jar anymore. Well I checked what happens when I exchange the v7 against the v13 and here are the method count numbers per package.
When using android-support-v4:
android.support: 10117
v4: 6402
v7: 3712
and when using android-support-v13:
android.support: 10203
v13: 82
v4: 6406
v7: 3712
Why are there still all methods from v4 (+4 additional ones?!) included in the v13 version? Reading http://developer.android.com/tools/support-library/features.html I thought the version number relates to the API level number.
When switching from support library v4 to v13 I expected the method count number to go down because now all the methods which are in the SDK version 13+ don't have to be in the support jar anymore.
No. support-v13 has everything that is in support-v4, plus additional classes that are only relevant for apps with a build target of API Level 13+.
Why are there still all methods from v4 (+4 additional ones?!) included in the v13 version?
Since the Android Support package pre-dated widespread Android use of things like Maven and Gradle, with transitive dependency support, Google elected to have support-v13 be a superset of support-v4. If they had to do it over again, they might have made support-v13 be a small JAR that depended upon support-v4.

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

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?
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.
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.
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.
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?
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!
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.

Categories

Resources