Android <uses-sdk> and Target Analytics

Source: Internet
Author: User

<uses-sdk> Properties and Target properties analysis in Android

1. Overview

<uses-sdk> used to describe the minimum and maximum API levels that the application can run , and the platform version that the application developer designed to run. By adding this attribute to the manifest manifest file, we have more control over the installation and compatibility experience of the app on different versions of the Android system.

                                                                                  

(Fig. 1)

As shown,<uses-sdk> through minsdkversion,targetsdkversion,maxsdkversion three properties control the application installation compatibility. Let's take a detailed description of these three properties in turn.


  2. Minsdkversion

The function of this property is mainly in two phases, one is when the application installs , and the other is when the project is built .


2.1. Installation-Time function

The app cannot be installed when the app's phone system API level is less than the value of minsdkversion.  

The minsdkversion is used to indicate the minimum API level required for the application to run. If this property is not specified, its default value is 1. Minsdkversion = "8" in 1 indicates that the application can only be installed on systems that are greater than or equal to Android system API Level 8 (android2.2). If you install the app on an Android system with an API level of less than 8, you will be prompted that the version of the mobile API is too low for the installation to fail.  

So here's a little bit of attention that we need to be aware of when we develop the API interface version. When defining the Minsdkversion attribute, try to make the value of minsdkversion greater than or equal to the minimum version of the API interface that we used to start being supported. This allows Android systems that do not support this interface to install our app and prevent apps from crashing on some phones due to compatibility issues.


2.2. The role of building a project

in the program, if we use API interfaces above the Minsdkversion value, Eclipse will automatically notify the developer of the error. Here we take Getactionbar () As an example, this interface appears in Android 3.0 (API leve 11). We see the program's development tool (Eclipse) detection of the program by setting the value of Minsdkversion.

    • As Minsdkversion = 8 o'clock, when we call the API level 13 interface, Eclipse automatically prompts the developer with an error:







Here we can choose [email protected] "NEWAPI" to deal with compilation errors through Eclipse's fix hint, but it is not recommended to solve the problem. This has escaped the compilation error, can successfully compile the apk file, but if the app is installed on a phone lower than the Android 3.0(API leve 13) system, it may cause a program crash ( higher than Android 3.0 (API leve 13) The system is installed on the phone properly). For an app to crash on the phone, it's better not to let the user install the app (personal view), of course, the need to consider the new API call frequency and the scene of a comprehensive sentence.

Here, Eclipse's @suppresslint ("Newapi") method is used to prevent error alerts.



The app crashes when you run it on an Android 2.3 (API Level 9) system.


  • At this point we can consider the ability to modify the value of minsdkversion to solve the problem, we set the value of Minsdkversion to 11.







all normal without error. When the Android system version is less than Android 3.0 (API level 11), the app will not install, and the Android system 3.0 or more is running properly.



2.3. Summary

We have seen the importance of minsdkversion from the above two points. minsdkversion not only works when the program is installed, it also works when the project is built . We should take full advantage of its two roles and carefully set its value to ensure that the application does not crash when running on some phones because of interface compatibility issues that affect the user experience .


3. Maxsdkversion

indicate the highest API level version that can run your app . It is not recommended to use this attribute in Google's official documentation.

on Android 1.5,1.6,2.0 and 2. 0. The system will check this value when installing an application or system upgrade on a 1 system. In both cases, if the maxsdkversion value of the app setting is lower than the API level used by the system itself, the system will not allow the app to be installed, and the new system will re-verify this value after the system upgrade, if the new system's API level is higher than this value, The new system will delete your app . On Android 2. 0.1 (API level 6) After the function of this attribute has been invalidated , it is also recommended not to use this property.

For example:



When you install the app on Android 2.3 (API Level 9), you can see that maxsdkversion is no longer working, and you can install the app when the system API is greater than maxsdkversion.



The new version of the system is basically completely compatible with previous versions of the old, there is no need to set this property to prevent your app from installing on the newer version, in addition, if you specify this property, A user's mobile system upgrade may erase your app . So this property is completely unnecessary to set up, which is probably why Google recommends no longer use it.


4. Targetsdkversion

This property tells the system that the application has been fully tested on a system with an API level of targetsdkversion value, and if the system has the same API and Targetsdkversion as the current application, The system will not enable compatibility mode to run the app, and if not set its default value will be equal to the value of minsdkversion.

Span style= "White-space:pre" > if the platform's API Level is higher than the value specified by the Targetsdkversion property in your application, the system turns on compatibility behavior to ensure that your application continues with your expect In general, the value of this property should be set to the latest API level value

Add new features when Android version update see:

Http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

If the platform's API level is lower than the value specified by the Targetsdkversion attribute in your application , the system will turn on compatibility behavior to ensure that your application works correctly. Then some of the features on the targetsdkversion are gone. However, this setting is only a declaration, a notification, and running in a low-version system will not be too substantial. For example: Using a feature in the SDK version of Targetsdkversion, but this feature is not supported in the low version, then when running the program on a lower version of the API device, you may get an error: Java.lang.VerifyError. That is, this property does not help you resolve the compatibility test problem. you need at least a complete run of the program on Minsdkversion this version to determine compatibility is no problem .

From the above discussion, targetsdkversion This attribute is in the program run time function, the system according to this property determines whether to run this program in compatibility mode.


5. Target

Android Project also has a target property, which is located in the Android project root directory project.properties, from the name it is easy to confuse its functionality and targetsdkversion.

In fact, they have different functions:

    • Targetsdkversion This has been done analysis, in the program run, the system according to this property determines whether to run the program in compatibility mode.
    • Project.Properties in the Target refers to the which version of the API is used for compiling when compiling . It is consistent with the API level of the API packages imported under the project. If you change the value of target, the API package will change, and the value of target will change when you change the API package.

6. Reference

(1) http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

(2) http://blog.csdn.net/zhangjg_blog/article/details/17142395

(3) http://blog.segmac.com/post/android-manifest-uses-sdk-element











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.