How to use android:targetSdkVersion and android:maxSdkVersion xml attributes?
The attributes android:minSdkVersion, android:maxSdkVersion let you specify the range of devices your app will support which will be used by Google to filter its content.
Say you have Android version 11 i.e. Honeycomb on you device and I make an app and I specify android:minVersion = "14" (i.e. ICS), then my app will not be shown in your device's Play Store, similarly the android:maxVersion serves the same purpose.
The attribute android:targetSdkVersion is used by the developers to specify the platform they are targeting the most, lets say 70% of Android device users have version 10 i.e Gingerbread on their phones so it will be a better option for the developer to test the app on 2.3 devices and specify android:targetSdkVersion to the same.
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
Description:
Lets you express an application's compatibility with one or more versions of the Android platform, by means of an API Level integer. The API Level expressed by an application will be compared to the API Level of a given Android system, which may vary among different Android devices.
Attributes:
android:minSdkVersion
An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute. You should always declare this attribute.
android:targetSdkVersion
This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).
android:maxSdkVersion
An integer designating the maximum API Level on which the application is designed to run.
In Android 1.5, 1.6, 2.0, and 2.0.1, the system checks the value of this attribute when installing an application and when re-validating the application after a system update. In either case, if the application's maxSdkVersion attribute is lower than the API Level used by the system itself, then the system will not allow the application to be installed. In the case of re-validation after system update, this effectively removes your application from the device.
More in Details
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eample.tut"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />****
<uses-permission android:name="android.permission.INTERNET"/>
<application
....
</application>
</manifest>
Just to add to what Alexis wrote, these XML tags are how the Google Play Store knows which devices your application can deploy to. It will also affect which levels of the API you can use during development. If you're ever wondering exactly how far back you should support, check out the pie graph on the Android Dashboard page to see the breakdown of current devices.
In your android manifest write (example):
<uses-sdk
android:maxSdkVersion="16"
android:minSdkVersion="10"
android:targetSdkVersion="10" />
See this for more informations.
Related
I made my game work on Android TV, it required Leanback library, which wants minSdkVersion to be 17. I must support API 16 too. What can I do?
When building, I get an error this suggestion:
Suggestion: use tools:overrideLibrary="android.support.v17.leanback" to force usage
What exactly does it do? Does it actually make my app still support API 16? What am I losing?
You can find the detailed information here.
Here is what it says:
tools:overrideLibrary marker
A special marker that can only be used with uses-sdk declaration to
override importing a library which minimum SDK version is more recent
than that application's minimum SDK version. Without such a marker,
the manifest merger will fail. The marker will allow users to select
which libraries can be imported ignoring the minimum SDK version.
And you need to do the following: In the main android manifest :
<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="2"
tools:overrideLibrary="android.support.v17.leanback"/>
Hope this helps.
Should I use android.maxSdkVersion in manifest.xml file? Because I read in documents that I should not use this in manifest.xml file. And as regards most version of android devices are 2.3 to higher. What is your opinion?
Google stated at Android Developers:
Warning: Declaring this attribute is not recommended. First, there is no need to set the attribute as means of blocking deployment of your application onto new versions of the Android platform as they are released. By design, new versions of the platform are fully backward-compatible. Your application should work properly on new versions, provided it uses only standard APIs and follows development best practices. Second, note that in some cases, declaring the attribute can result in your application being removed from users' devices after a system update to a higher API Level. Most devices on which your application is likely to be installed will receive periodic system updates over the air, so you should consider their effect on your application before setting this attribute.
Syntax:
<uses-sdk
android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
However if you use the new Gradle then android:minSdkVersion="integer" and android:targetSdkVersion="integer" will always be overridden in the Gradle scripts.
I suggest you not to use it.
Here is a guide for more detailed information:
Android Developers - uses-sdk-element in manifest
I'm developing a Android library and I want to support as many API versions as possible. I have stumbled upon a problem with AsyncTask and found an answer here on SO. The proposed code to use is:
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute(params);
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
My question is, how do I include the proposed code AND support lowest possible API level? What API version should I reference? What should I write in the uses-sdk tag inte manifest?
Since the field THREAD_POOL_EXECUTOR in AsyncTask is only available from API level 11. Can this code be compiled to a lower level?
Thanks!
Assume that you line below exists in you manifest
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
This means that you are using features from API-17 but to ensure backwards compatibility your application may start on minimum API-8 (Froyo).
According to your example, using THREAD_POOL_EXECUTOR for API-17 or lower is OK. And running your code with Froyo device is OK too. Because THREAD_POOL_EXECUTOR field will not be used in this case.
In the manifest set android:minSdkVersion="minimumApiYouNeed", this is the lowest api you want to support, and the android:targetSdkVersion="maximumApi". This is the api that will be used to compile the code. This way you will be able to do things like what you wrote there, if you ever write something that is not supported by the minimum api, the editor will notify you, but it will work well if you do the checking it will work well
You will have to use API level 11 or higher unless you can find a library that works on an earlier API level that provides the THREAD_POOL_EXECUTOR implementation. Also, check to see if Google provides any backports or support libraries that would allow this to work before API 11.
This supports Android back to 2.1 (sdk version 7), but compiles the code against sdk version 17 (HoneyComb). You would have to add that tag to your manifest, of course.
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
Your project.properties should include this line:
# Project target.
target=Google Inc.:Google APIs:17
Currently, I have a piece of code, which is designed to run both in Android 2.3 and 4+
The code will perform much better (Where it will not have OutOfMemory exception most of the time), if android:largeHeap is being applied in AndroidManifest.xml.
<application
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="nosensor"
android:largeHeap="true"
Currently, my android:minSdkVersion need to set to 15 instead of 10 (Android 2.3). If not, android:largeHeap is not allowable in AndroidManifest.xml.
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
Within single APK, how possible I can set
Use android:largeHeap option if I were in Android 4+
Do not use android:largeHeap option if I were in Android 2.3
You can also disable large heap in Honeycomb and enable it in ICS or JB. Just a little hacky or something. Here's what I tried.
Before we proceed, change your Build target to Honeycomb, Jelly Bean or ICS so we can put android:largeHeap attribute. Also, you can set android:minSdkVersion to API 10.
Android API 10 doesn't support large heap.
Create a folder values-v14 in res folder
I created bools.xml in values-v14
Put this value in bools.xml of values-v14
<bool name="largeheap">true</bool>
boolean value for values > bools.xml or values-[API VERSION] > bools.xml to disable large-heap in different API Version or by default.
<bool name="largeheap">false</bool>
Change the value of android:largeHeap to #bool/largeheap instead of hardcoded true or false
<application
android:largeHeap="#bool/largeheap"
android:allowBackup="true"
android:icon="#drawable/ic_launcher">
....
</application>
I tested this code by making a memory leak application or just load a Huge bitmaps, and, its working!
Good Luck!
Keep the android:largeHeap="true" attribute in your AndroidManifest.xml. This should be ignored for versions that don't support it. Then, to support older versions, set the heap size using the VMRuntime class (via reflection, if necessary).
More on this topic: How to increase heap size of an android application?
1.Build project with target Android 3.0 (API 11) or above.
(Project properties - Android - Project Build Target - select above API level 11)
in Manifest file, Change the uses-sdk value as following
< uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="11" />
For prior versions of Android 3.0, you can use VMRuntime class for memory manipulations.
Seems that you have incorrect target sdk in project.properties file, check it out and change target to your AndroidManifest`s targetSdk (15) and rebuild project.
project.properties
# Project target.
target=15
P.S. I tryed add android:largeHeap to my Project (minSdk = 7, targetSdk = 17) compiled and run normally on all Android versions.
Please change project properties:
In project Properties -> Android -> Project Build Target -> Google API, API level 19 (or any other you need) :)
So your can leave your minimum SDK option without change, for example 8 :)
I want to add android:tragetSdkVersion= "14" in my manifest but I'm consufed as initially I developed my application for 2.3.3 version. So I used TabActivity for that. But TabActivity is deprecated in 4.0 version and according to the documentation, including android:tragetSdkVersion= "14" means system will not impose any forward compatibility to the app. So I wonder if it is good idea to include android:tragetSdkVersion= "14" in my manifest.
If you want to make it working on sdk 14, why are you leaving TabActivity in your code?
Otherwise, don't make sdk14 your target, and better to prevent users with version 4.0 or higher to install your application
You should use the v4 support libraries if you target higher SDK versions and also provide a minSdk:
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
here is info about the support libraries
http://developer.android.com/tools/support-library/index.html