I have a problem while building my android project due to some missing android-support-library (i.e: android-support-v7.jar) so to fix it I had to add an Android Support Library from eclipse wizard. However I was surprised that my $android_sdk_home/extras/andoird/support/v7/appcompact/libs contains android-support-v4.jar and android-support-v7-appcompat.jar. Is that normal?
If I understood you correctly, you're wondering if having both v4 and v7 support libraries is normal. It is perfectly normal as they have different purposes. Basically they provide you with widgets and APIs to be used respectively in API levels 4 and 7 and beyond. They also provide different interfaces.
You can read about it here in more detail: https://developer.android.com/topic/libraries/support-library/features.html
Related
Question:
When should be used android.support.* packages, and when android.*?
Would love next facts considered while answering:
Not required to support old android versions
ViewPager and other features available in support-only are desired
If it can always be done in support, then why bother with native library?
Can support/native library be disabled in IDE, so that I stop accidentally importing wrong packages?
Support library is used to make your app capable to run on android lower versions also.
You should definitely read the documentation.
android.support.* is used to support older devices that does not have new Android API.
For example, Fragments were introduced from HONEYCOMB, that's why you should use support package, if you are planning to support Android 2.*.
I am not fully certain that I am not making any mistakes when setting API level when developing under Eclipse so here are some examples which I am not 100% certain about.
When developing Android app in Eclipse I always set BuildProjectTarget under Eclipse and android:targetSdkVersion in the manifest to the latest available Android version. Is this practice correct? NOTE:I do set android:minSdkVersion according to the project (usually value is 10)
I know that doing the above will trigger Eclipse warning about unsupported API when using something not available in version under android:minSdkVersion (for example using fragments without support library) are there any examples when these shouldn't be trusted and what will happen if you build the project using Gradle/Ant script or manually?
What would happen if I set BuildProjectTarget and android:targetSdkVersion to for example 16 and then use some deprecated API like WebView setCertificate() (which was deprecated in API level 17). Will this method work on all devices or just those up to Android 4.1, will it crash the app or just be ignored?
I know that Eclipse uses Java library android.jar from SDK/platforms folder and that when on the device app links to that library stored on device but what I don't get is are there multiple versions of this library on android phones or just one (the latest for that android version) ? Also does a version of framework.jar play a role in this?
What happens with the libraries when you use something like google_play_services? Are these packed into the apk or reference the library that is already on the device? I know that when you use Facebook sdk the jar gets packed into apk but don't know are these google libraries different?
Yes this practice is correct and is done to ensure support for the latest android versions.
When you set a minSdkVersion, then that's thr lowest version of Android your app will support and compiling with ant/gradle will show errors ehen you will use methods introduced in newer api levels for an older one.
Deprecated means that another method has replaced this one and that this one will spon be removed from the Android source code, so developers are encouraged not to use them. But yes they will work until they remain in the source.
The android.jar is a dependency of the methods and stuff included in the android OS, stuff that you'd be able to call and no I don't think framework.jar plays a role in this.
All external libraries are referenced and added to the apk. BUT only some of the google ones, those that are not primary. (Take a look at the gapps packages, that'll give you some specifics. Link: http://goo.im/gapps)
I hope I got this right and helped you to understand.
When developing Android app in Eclipse I always set BuildProjectTarget under Eclipse and android:targetSdkVersion in the manifest to the latest available Android version. Is this practice correct? NOTE:I do set android:minSdkVersion according to the project (usually value is 10)
Yes. That way you ensure you're always using the latest build sdk.
I know that doing the above will trigger Eclipse warning about unsupported API when using something not available in version under android:minSdkVersion (for example using fragments without support library) are there any examples when these shouldn't be trusted and what will happen if you build the project using Gradle/Ant script or manually?
Just make sure that older devices will not get to that part of the code, using Build.Version.SDK_INT. This will give you the current SDK of the device.
What would happen if I set BuildProjectTarget and android:targetSdkVersion to for example 16 and then use some deprecated API like WebView setCertificate() (which was deprecated in API level 17). Will this method work on all devices or just those up to Android 4.1, will it crash the app or just be ignored?
Deprecated methods will continue to work, but better alternatives are available. When you have the option to use that better alternative, use it. When you're supporting devices that don't have this alternative yet due to older versions, continue using the deprecated method. You might have to do some if else branching based upon the Build.Version.SDK_INT value.
I know that Eclipse uses Java library android.jar from SDK/platforms folder and that when on the device app links to that library stored on device but what I don't get is are there multiple versions of this library on android phones or just one (the latest for that android version) ? Also does a version of framework.jar play a role in this?
The newer devices contain the code of the older devices. Therefore it is not necessary to keep references to other versions.
What happens with the libraries when you use something like google_play_services? Are these packed into the apk or reference the library that is already on the device? I know that when you use Facebook sdk the jar gets packed into apk but don't know are these google libraries different?
The class files in the jar will be packaged in the .apk. The Google Play Services on the device communicates with your app using those classes.
I am trying to use the code template provided by android in eclipse and I set my min SDK to API 8. I tried to choose the "blank activity with scrollable tab" for using the swipe feature but it wouldn't let me continue and complaining that this code template support version 11 and more.
However, I thought that's why the support library of version 4 is! To support Api 4 and above.
Am I missing the point here or is there something I need to do?
Thank you
Use the android.support.v7 compatibility libraries (which work together with the v4 libraries).
When you create the project in eclipse set the minimum API version to 11 but once the project is created, edit AndroidManifest.xml to set minSDKVersion to 8.
From time to time when building the project, eclipse may complain about min SDK version being required for certain things - in this case just Clean the project and it will build without problems.
I have gotten it to work using ActionBarSherlock and ViewTabPager. Look into those
http://developer.android.com/training/implementing-navigation/nav-drawer.html
I have implemented this feature, it quite well works on android 4.0 and up.
But I need to make this project compatible with android 2.2, 3.0 etc.
I tried to add android-support library but it does not work, since someone suggested to do so.
How can I achieve my goal?
It should work with adding the support v4 library jar. However, it is recently added and using an older version of this jar will result in errors.
Update your ADK & ADT and start a new Android project. This will create a new project with the latest and greatest support v4 library. Just copy-paste that in your libs/ folder of your own project to replace the old one.
I want to build a Calculator App, in which I want to format all the required buttons in such a way that, they all appears in a Grid form to me....
The one which I've made is only running on Android 4.0 & above devices...But I want that my calculator app should run on maximum Android devices(Android 2.2 & above) & which have a GridLayout in it..!
Please help me by suggesting me some code or anything else...
Thanx!
A backwards compatible implementation (for API level 7 and up) of GridLayout is also available as Android library project in the support library. After you've downloaded this add-on, you'll find an Android library project in your local sdk folder located at:
<sdk_folder>\extras\android\compatibility\v7\gridlayout
Set it up as dependency of the project you're working on. After that, you'll need to change the references throughout your project from the level 14 version to this compatibility one in order to support pre-ICS devices. Usage should be similar, if not identical.
See also:
GridLayout in Android 2.0?
Grid Layout support in android API 10