I'm really not experienced with Android.
As mentioned in Difference between android-support-v7-appcompat and android-support-v4 there are multiple various support libs in the Android. The official Android article http://developer.android.com/training/appbar/setting-up.html on using Toolbar states that I need to use v7 appcompat lib. The problem is... I don't wanna use it, as it makes a mess with everything in the code.
So, is there a way to have a toolbar without using this support lib (v7), since I need only support for Android API level >= 15 (ver. 4.0+), not 2.* or sth? If not, how could I implement it? (This class http://developer.android.com/reference/android/support/v7/widget/Toolbar.html suggests v7 lib is needed).
Further more, is it possible to force Android Studio IDE to generate projects that use no this Compat Support library? (So that I'm not required to change everything related to it - and this includes a lot of work with e.g. theme resource files - so that there's no relations to this support lib)?
Related
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.
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.
I see some examples use
compile 'com.android.support:appcompat-v7:21.0.3'
and some show:
compile 'com.android.support:support-v7:21.0.3'
What is the difference between these two libraries?
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 appcompat library
This library adds support for the Action Bar user interface design pattern. This library includes support for material design user interface implementations.
Note: This library depends on the v4 Support Library. If you are using Ant or Eclipse, make sure you include the v4 Support Library as part of this library's classpath.
Source: https://developer.android.com/tools/support-library/features.html
AppCompat (At first ActionBarCompat) started out as a backport of the Android 4.0 ActionBar API for devices running on Gingerbread, providing a common API layer on top of the backported implementation and the framework implementation. AppCompat v21+ delivers an API and feature-set that is up-to-date with Android 5.0 like some material styles and themes as well as some Android 5 components like cardview and palette library.
As you can see AppCompat is mostly about making new android app design concept available in older versions.
Support Library on the other hand tries to provide functionalities of new version of android in older versions like fragments. It also has some useful classes which are not present in any version of android like ViewPager, LruCache and LocalBroadcastManager.
I'm trying to set ActionBar in my android application for targets 8-18 using the support libraries. With the official statement of Android, the use of ActionBar is based on Theme.AppCompat of support library v7. I followed the official guide http://developer.android.com/tools/support-library/setup.html (section "Adding libraries with resources" using eclipse) and the ActionBar was well performed. But since I need to avoid adding libraries with resources, I want to export a .jar file of support library v7 and add it into lib folder of my app, the android:theme="#android:style/Theme.AppCompat.Light" causes error: No resource found that matches the given name (at 'theme' with value '#android:style/Theme.AppCompat.Light'). Also, if I simply add the android-support-v7.jar, I'm not allowed either to use Theme.AppCompat. So anyone could figure out how to export .jar of the support library v7 resources which could be added in the way of "adding library without resources" to allow the Theme.AppCompat? Thanks in advance.
So anyone could figure out how to export .jar of the support library v7 resources which could be added in the way of "adding library without resources" to allow the Theme.AppCompat?
That is not possible. AppCompat and ActionBarSherlock -- the two leading action bar backports -- make very heavy use of resources. It is not just Theme.AppCompat (or ABS's equivalent, Theme.Sherlock), but colors and dimensions and drawables and layouts and strings and more. You can tell that by looking at the source code of each project.
You are welcome to attempt to write your own action bar backport library that somehow eschews resources.
Or, if you happen to be using Android Studio and the new Gradle-based build system, simply require the AppCompat AAR file, and the resources will be taken care of for you.
I have created a new android project in Eclipse, and I have setted this configuration:
Minimum required SDK: API 7
Target SDK: API 18
Compile with: API 18
Theme: Holo Light
So, my application has the actionbar. Eclipse has automatically included only android-support-v4.jar.
But, since ActionBar class is included in the support library for compatibility with API level 7 and higher. I am wondering why in my project are included only android-support-v4 library.
I guess that if I don't include v7 appcompat library I can continue to show the actionbar in my application, but I can't manage or customize it using ActionBar API? Is this right?
Quoting from the docs
The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.
http://developer.android.com/guide/topics/ui/actionbar.html
If you want your app to support action bar below 3.0 you need to use app compact v7 from the support library.
Also check the below link
http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html
you need to understand some of the very basic things.
1) Support libraries are meant to support functionalities in previous versions. you need to manually setup your project(addition in build path etc) to use support libraries.
2) If you dont use support library v7 in this case, You can show action bar, can customize it and do whatever it is supported in the version(3.0) ActionBar supported in.
3) If you want to show Action Bar in suppose Api levels 8/7(2.2/2.1), you must use support libraries v7.
Here is how to create action bars and support it lower versions
Please dont forget to use/imports classes/apis from support library instead of SDKs classes.
Tutorial is easy enough to understand.
1) Support libraries are meant to support functionalities in previous versions and add functionalities that only exists in these libraries. You need to manually setup your project(addition in build path etc) to use support libraries.