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.
Related
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.
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
This question already has an answer here:
How do make sure there is no conflict of "v7 appcompat or support" of my library when any application uses my library?
(1 answer)
Closed 6 years ago.
I have a android library with com.android.support:appcompat-v7:23.0.1 dependency in the gradle with compliedSDK of 23
I have following doubts
case 1) Say any applicaion with different version com.android.support:appcompat-v7:23.3.0 uses my library.
which version does the android take? Lower one or Higher one? How do i see it?
How do i make sure there is no conflict of v7 appcompat when any app uses my library?
case 2) Say any applicaion with different version com.android.support:appcompat-v7:25.0.1 or com.android.support:appcompat-v7:24+ and different compiledSDk(24 or 25) uses my library.
I know that The support library should not use a different version than the compileSdkVersion.
How does the android merge the support libraries now? (Since the support library version(appcompat-v7:23.0.1) of my library is different from that of the application's compiledSDK (25) )
How do i make sure there is no conflict of v7 appcompat when any app uses my library?
Anyone Please clear my doubts
which version does the android take? Lower one or Higher one? How do i see it?
When building library you put the dependency explicitly in build.gradle. The same is done by the creator of app, that uses your library as a dependency declared in his build.gradle. If the creator explicitly declares support library as a dependency, that version is taken (regardless the versions declared by dependencies). If he does not do that, the highest version declared by any dependency is taken (such support library is regarded as a transitive dependency).
Example: Your library uses appcompat-v7:23.3.0. The creator of app declared appcompat-v7:25.0.1. Simple case: appcompat-v7:25.0.1 is taken.
Example 2: Your library uses appcompat-v7:23.3.0. The creator of app does not use appcompat-v7. appcompat-v7:23.3.0 will be in output app.
Example 3: Your library uses appcompat-v7:23.3.0. Another library uses appcompat-v7:24.1.0. If the creator does not explicitly declare appcompat-v7:xx.x.x the version appcompat-v7:24.1.0 will be in output app.
Hope you understand.
How do i make sure there is no conflict of v7 appcompat when any app uses my library?
You can't assure that. That is why you should always put the highest version of support libraries in the library. I can't even assure you the support libraries maintain backward compatibility. Here is the example that they don't.
I know that The support library should not use a different version than the compileSdkVersion.
That is only a suggestion. However, you should conform to it, but you don't have to.
I want to add multiples libraries on Android, but every one of them have the support library v4, and need them. I want to add : android-support-v7-appcompact, facebookSDK, PullToRefresh, google-play-services_lib.
I have DEX errors and NoClassDef errors every time.
For each project right click > Android Tools > Add Support Library
Although the support library is already added to the project it will download and install the latest version of the support library.
If you do this for each library project you should no longer see the error.
Hope this helps.
If the support library versions are not same there'll be error.
Either copy one of the support library v4 to all of them or delete all of the support libraries and just leave one of them
I'm currently working on a project where I use multiple libraries. Multiple libraries use the android support library, so when I want to compile my app Eclipse complains about it with a Dalvik error. I already found out that I should only have the support library 1 time in my project. But, this breaks the library projects which causes that I cannot compile anymore.
How should I properly handle this?
If you use support library such as v4 and your project contains other library projects, you should keep the only one version of the v4 library. Choose one of the library file (the one that has the biggest size for example), remove all the duplicates and then copy this v4 into each project library which uses it.
Check if any of your libraries include the support library already. Maybe it's failing because it's already included.