Android in build target,minsdkversion,targetsdkversion,maxsdkversion concept distinction

Source: Internet
Author: User

Android in build target,minsdkversion,targetsdkversion,maxsdkversion concept distinction

2014-01-23 13:14 10937 People read review (16) Favorite Report

Classification:

Android(+)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directory (?) [+]

This article refers to the Google Developer Documentation: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#provisional

If you are developing more application users, you must ensure that the application works correctly on multiple versions of the device. This requires familiarity with each version, knowing what new features or features were added to the version. But there are too many versions of Android, which is a daunting issue. If you want to learn about Android version differences, it is recommended to read the relevant chapters on the Android developer documentation.

In order for your application to specify a version that can run, the <uses-sdk> tag is available in the Android manifest file. There are three attributes in the tag, namely minsdkversion,targetsdkversion,maxsdkversion. These three attributes are easy to confuse, and I read Google's official documents carefully before figuring out the meaning of these three attributes. In addition, there is a concept called build target when the project is built, which is also analyzed in this article.

What is API level

In fact, the label <uses-sdk> does not specify the version of the SDK we use, not the version of the Android system, but we use the version of the Android platform, the API level. API level is an integer that refers to the version of the framework (framework) we use, which is the Android.jar under each platform in the SDK we use. But this API level is also related to the version of the Android system, and each system will internally record the API level it uses. For example, I use the mobile phone system is Android 2.3.3, then it will be in the internal record using the API level of 10. This internal API level allows the system to determine whether an app can be installed, which is mentioned later in this article.

The corresponding relationship table between Android version, API level and version code is given below. (This form is from Google's Official document: Http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#provisional)

As can be seen from the above table, Android's system version and API level is not one by one corresponding, such as Android 2.3, Android 2.3.1, Android 2.3.2 corresponding API level 9, while Android 2.3.3, Androi D 2.3.4 corresponds to API level 10. The API level is a set of framework (ANDROID.JAR) codes that Android provides to developers, possibly releasing a new version of the system, but this set of interfaces does not change, so there is no need to provide a new framework development package, so the API Level does not have to change. The Android system version and API level are the many-to-one relationships. Since API level is the code name for the published Android.jar (set of interfaces), each Android.jar in the platforms directory in the API level and the SDK corresponds to one by one. To put it bluntly, the Android version is for Android users, and the API level is for app developers to see.

What is build target

The build target does not exist in the manifest file, but it exists in the Project.Properties file in the root directory of the project. If you build your project with eclipse, there will be a project.properties file in the root directory of each project that tells the build system how to build the project. Open this file with the following line in addition to the comment:

Target=android-18

The phrase is to specify the build target, which is based on which Android platform to frame the project. Specifies that the build target is android-18, which compiles the project using Android.jar in the ANDROID-18 directory under the platforms directory in the SDK. Again, this android.jar will be added to the build path of this project. Such as:

Whenever you modify the build target, another Android.jar is added to the build path to replace the original jar. The effect of changing the build target to ANDROID-17 is as follows:

If you change the build target to Android-8, Then the project will be compiled using the Android.jar in the SDK, and if Actionbar related APIs are called in the activity, the error will be android-8 because the Actionbar related APIs are added in API level 11.

In general, you should use the latest API level as the build target. This is also the default behavior when eclipse builds the project.

Android:minsdkversion

Indicates the minimum API level required for the application to run. If not specified, the default is 1. This means that the app is compatible with all Android versions. We should always declare this attribute.

If the system's API level is lower than the value set by Android:minsdkversion, then the Android system will prevent users from installing the app. The download sets Android:minsdkversion to 11 and installs the app on Android 2.3 's phone (corresponding to API Level 9), which prompts you when installing:


Tip The phone API level version is too low, the installation fails.

If this attribute is indicated and an API above this API level is used in the project, then the compile times are wrong. Set the build target to the latest android-19, and the project will be compiled with the latest Android.jar under ANDROID-19. Set Minsdkversion to 8. In the Android.jar used, there will definitely be an API associated with Actionbar, but the project will have an error calling the Actionbar API in the project. There is no Actionbar-related API in the API level 8 indicated by minsdkversion.

Calling the Activity.getactionbar () and Actionbar.getheight () methods requires API level 11, but the specified minsdkversion is 8, so an error is given. This shows that minsdkversion not only works when the program is installed, it also works when the project is built.

If the Minsdkversion property is not set, then the default is 1. Indicates that the program is compatible with all Android systems and is capable of running on all Android systems. If you are using an API higher than API level 1, such as Actionbar. Then when building the project, you will be prompted with the same error above and the project build fails.

Android:targetsdkversion

An integer that identifies the application target API level. If not set, the default value is the same as minsdkversion.

This property notifies the system that you have tested your program against this specified target version, and the system no longer has to use compatibility mode to make your application forward compatible with this target version. Applications can still run on systems that are less than targetsdkversion.

As Android continues to evolve toward newer versions, some behaviors, even appearances, may change. However, if the platform's API level is higher than the value specified by the Targetsdkversion attribute in your application, the system will turn on compatibility behavior to ensure that your application continues to run in the desired form. You can disable this compatibility behavior by specifying targetsdkversion to match the API level of the platform on which the program is running. For example, setting this value to 11 or higher, when your app is running on a Android3.0 or higher system, uses the new default theme (Holo theme) for your app, and disables screen compatibility mode when running on a device on a large screen Compatibility mode), since support for API level 11 implies support for large screens.

Depending on the value of the targetsdkversion you set, the system performs many compatibility behaviors. Some behaviors are discussed in the build.version_codes of the corresponding platform version.
In order for your application to support each Android version, you should increase the value of Targetsdkversion to the latest API level and test your application thoroughly on the corresponding platform.

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.

In general, you should set the value of this property to the latest API level value, so that you can take advantage of new features on this system. When Eclipse builds the project, the value is set to the highest by default, and if a lower value is set, a warning is given, as shown in.

This warning means that the Targetsdkversion value is not set to the highest value, and the newer system runs the program in compatibility mode. Consider testing the program on a new version of the system and setting Targetsdkversion to the latest. For more detailed information, please refer to Android.os.Build.VERSION_CODES.

Android:maxsdkversion

Indicate the highest API level version that can run your app.
In Android1.5, 1.6, 2.0, and 2.0.1, this value is checked when installing an application or system upgrade. 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. After the system upgrade, the new system will re-verify this value, if the new system's API level above this value, the new system will delete your app.
On systems higher than 2.0.1, installing an app no longer validates the Maxsdkversion value set in the app, and does not re-verify the value after the system has been upgraded. However, Google play continues to filter using this property when showing users the available apps.

Maxsdkversion This property is supposed to work when the program is installed and after the system has been upgraded. However, it is no longer recommended to use this property, as described in the official documentation.

After testing, set the value of the maxsdkversion to 9, the program can be installed on 4.2 of the phone. Indicates that the value is no longer working.

[HTML] view Plaincopy

    1. <uses-sdk
    2. Droid:minsdkversion= "8"
    3. android:targetsdkversion= "19"
    4. android:maxsdkversion= "9"/>

Android in build target,minsdkversion,targetsdkversion,maxsdkversion concept distinction

Related Article

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.