Android Developer官网API指南uses-sdk

  • Post author:
  • Post category:其他


SYNTAX:

<uses-sdk android:minSdkVersion="integer"
          android:targetSdkVersion="integer"
          android:maxSdkVersion="integer" />

CONTAINED IN:



<manifest>

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.

让你通过一个API级别的整数来表明这个应用在一个或多个Android平台的兼容性,应用所表示的API级别会和一个给定的安卓系统的API级别进行比较,这在不同的安卓设备上

可能

有所差异。

Despite its name, this element is used to specify the API Level,

not

the version number of the SDK (software development kit) or Android platform. The API Level is always a single integer. You cannot derive the API Level from its associated Android version number (for example, it is not the same as the major version or the sum of the major and minor versions).

尽管它的名字用来指定API级别,而不是SDK(软件开发工具包)的版本号或Android平台。但API级别始终是一个整数,你不能从其关联的Android版本号

得出

API级别(例如,它的主要版本或主要版本的和与次要版本

是不一样的

)。

Also read the document about

Versioning Your Applications

.

同时请参阅文档

Versioning Your Applications


.


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.


Caution:

If you do not declare this attribute, the system assumes a default value of “1”, which indicates that your application is compatible with all versions of Android. If your application is

not

compatible with all versions (for instance, it uses APIs introduced in API Level 3) and you have not declared the proper

minSdkVersion

, then when installed on a system with an API Level less than 3, the application will crash during runtime when attempting to access the unavailable APIs. For this reason, be certain to declare the appropriate API Level in the

minSdkVersion

attribute.

指定为运行应用程序所需的最低API级别的

一个整数



如果系统的API级别比该属性指定的值低,

Android系统会阻止用户安装应用程。你应该总是声明这个属性。

注意:如果你不声明这个属性,系统假定为“1”的默认值,这表示您的应用程序与Android的所有版本兼容。如果你的应用不是

兼容

所有版本(例如,它使用API​​等级3中引入的API),具有API级别小于3的系统上安装时,你还没有宣布正确的minSdkVersion,那么,该应用程序

运行时

将在

试图访问不可用的API时

崩溃。出于这个原因,一定要声明在的minSdkVersion属性相应的API级别。




android:targetSdkVersion

An integer designating the API Level that the application targets. If not set, the default value equals that given to

minSdkVersion

.

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

).

As Android evolves with each new version, some behaviors and even appearances might change. However, if the API level of the platform is higher than the version declared by your app’s

targetSdkVersion

, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect. You can disable such compatibility behaviors by specifying

targetSdkVersion

to match the API level of the platform on which it’s running. For example, setting this value to “11” or higher allows the system to apply a new default theme (Holo) to your app when running on Android 3.0 or higher and also disables

screen compatibility mode

when running on larger screens (because support for API level 11 implicitly supports larger screens).

There are many compatibility behaviors that the system may enable based on the value you set for this attribute. Several of these behaviors are described by the corresponding platform versions in the


Build.VERSION_CODES


reference.

To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version.

Introduced in: API Level 4

一个整数,指定

应用程序的



目标

API级别。如果没有设置,默认值等于该给的minSdkVersion。

此属性通知您已经对目标版本和系统不应使任何兼容的行为,以保持与目标版本的应用程序的向前兼容性测试系统。该应用程序仍然可以在旧版本(高于minSdkVersion)运行。

由于Android的每个新版本的发展,一些行为,甚至出现可能会改变。但是,如果平台的API级别比你的应用程序的targetSdkVersion所声明的版本时,系统会启用兼容的行为,以确保您的应用程序按

你期望的方式

继续工作。您可以通过指定targetSdk Version来匹配它的运行平台的API级别禁用这种兼容性的行为。例如,在Android 3.0或更高版本上运行时还会禁用屏幕兼容模式,在更大的屏幕上运行(将该值设置为“11”或更高允许系统应用一个新的默认主题(Holo)您的应用程序,因为API支持11级隐含支持更大的屏幕)。

有迹象表明,该系统可以使基于您为此属性设置的值很多兼容性的行为。这些行为是由在Build.VERSION_CODES参考相应平台的版本中描述。

为了保持与每个版本的Andr​​oid沿着你的应用程序,您应该增加这个属性来匹配最新的API级别的值,然后在相应的平台版本全面测试您的应用程序。




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.

To illustrate how this attribute can affect your application after system updates, consider the following example:

An application declaring

maxSdkVersion="5"

in its manifest is published on Google Play. A user whose device is running Android 1.6 (API Level 4) downloads and installs the app. After a few weeks, the user receives an over-the-air system update to Android 2.0 (API Level 5). After the update is installed, the system checks the application’s

maxSdkVersion

and successfully re-validates it. The application functions as normal. However, some time later, the device receives another system update, this time to Android 2.0.1 (API Level 6). After the update, the system can no longer re-validate the application because the system’s own API Level (6) is now higher than the maximum supported by the application (5). The system prevents the application from being visible to the user, in effect removing it from the device.


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.

Introduced in: API Level 4

Future versions of Android (beyond Android 2.0.1) will no longer check or enforce the

maxSdkVersion

attribute during installation or re-validation. Google Play will continue to use the attribute as a filter, however, when presenting users with applications available for download.
一个整数,指定该应用程序设计运行的最大API级别。

在Android 1.5的,1.6,2.0和2.0.1,系统中安装一个应用程序时重新验证系统更新后的应用程序时,检查此属性的值。在这两种情况下,如果应用程序的maxSdkVersion属性是比由该系统本身所使用的API级别较低,则系统将不会允许安装该应用程序。在系统更新后,再验证的情况下,这有效地将删除设备应用程序。

为了说明这个属性怎么能系统更新后会影响您的应用程序,考虑下面的例子:

在其应用程序清单声明maxSdkVersion =“5”发布在谷歌播放。其设备运行的是Android 1.6(API等级4),下载并安装应用程序的用户。几个星期之后,用户会收到过空中系统更新到Android 2.0(API级别5)。安装此更新后,系统会检查应用程序的maxSdkVersion并成功重新验证它。应用功能正常。然而,一段时间后,该设备接收其他系统的更新,这次到Android 2.0.1(API级别6)。更新后,系统可以不再重新验证的应用,因为该系统自身的API级别(6)现在比由应用程序支持的最大增加(5)。该系统阻止应用程序是对用户可见,实际上从装置移除。

警告:本声明属性不推荐使用。首先,有没有必要设置属性,他们被释放阻止你的应用程序到Android平台的新版本的部署方式。根据设计,该平台的新版本完全向后兼容。您的应用程序应该在新的版本中正常工作,只要它仅使用标准的API,并遵循开发的最佳实践。二,请注意,在某些情况下,宣布该属性可能会导致您的应用程序的系统升级到更高级别的API之后,从用户的设备中移除。在您的应用程序很可能将安装在空中定期收到系统更新大部分设备,所以你应该设置该属性之前考虑它们对你的应用效果。

INTRODUCED IN:

API Level 1

What is API Level?


API Level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform.

The Android platform provides a framework API that applications can use to interact with the underlying Android system. The framework API consists of:

  • A core set of packages and classes
  • A set of XML elements and attributes for declaring a manifest file
  • A set of XML elements and attributes for declaring and accessing resources
  • A set of Intents
  • A set of permissions that applications can request, as well as permission enforcements included in the system

Each successive version of the Android platform can include updates to the Android application framework API that it delivers.

Updates to the framework API are designed so that the new API remains compatible with earlier versions of the API. That is, most changes in the API are additive and introduce new or replacement functionality. As parts of the API are upgraded, the older replaced parts are deprecated but are not removed, so that existing applications can still use them. In a very small number of cases, parts of the API may be modified or removed, although typically such changes are only needed to ensure API robustness and application or system security. All other API parts from earlier revisions are carried forward without modification.

The framework API that an Android platform delivers is specified using an integer identifier called “API Level”. Each Android platform version supports exactly one API Level, although support is implicit for all earlier API Levels (down to API Level 1). The initial release of the Android platform provided API Level 1 and subsequent releases have incremented the API Level.

The table below specifies the API Level supported by each version of the Android platform. For information about the relative numbers of devices that are running each version, see the

Platform Versions dashboards page

.

什么是API级别?

API级别是一个整数值,它唯一标识一个版本的Andr​​oid平台所提供的框架API版本。

Android平台提供了一个框架的API,应用程序可以使用与底层的Andr​​oid系统进行交互。该框架API包括:

  • 一套核心包和类
  • 一种声明manifest文件组XML元素和属性
  • 一个声明和访问资源组XML元素和属性
  • 一组的意图
  • 一组权限程序能够请求,以及允许执行进包括在系统中
  • Android平台的后续版本可以包括更新Android应用程序框架的API

更新到框架层的API设计,以使新的API保持与较早版本的API兼容。也就是说,在API中大多数都是添加和引入新的或替换功能。作为API的部分升级,老替换的部分已被弃用,但不会被删除,从而使现有的应用程序仍然可以使用它们。在极少数的情况下,该API的部分可以被修改或删除,尽管仅需要典型地这样的改变,以确保API鲁棒性和应用程序或系统的安全性。从早期版本的所有其他API部分无需修改。

该框架API,一个Android平台提供使用称为“API级别”的整数标识符指定。每一个Android平台的版本完全相同支持一个API水平,虽然支持是隐含的所有早期的API级别(最低API级别1)。 Android平台的初始版本提供的API Level 1和后续版本都增加了API级别。

下表指定了Android平台的每个版本支持的API级别。有关设备的相对数字,正在运行的每个版本的信息,请参阅平台版本的



Platform Versions dashboards page


.


API Level VERSION_CODE Notes

Android 7.0

24


N


Platform Highlights

Android 6.0

23


M


Platform Highlights

Android 5.1

22


LOLLIPOP_MR1


Platform Highlights

Android 5.0

21


LOLLIPOP

Android 4.4W
20


KITKAT_WATCH

KitKat for Wearables Only

Android 4.4

19


KITKAT


Platform Highlights

Android 4.3

18


JELLY_BEAN_MR2


Platform Highlights

Android 4.2, 4.2.2

17


JELLY_BEAN_MR1


Platform Highlights

Android 4.1, 4.1.1

16


JELLY_BEAN


Platform Highlights

Android 4.0.3, 4.0.4

15


ICE_CREAM_SANDWICH_MR1


Platform Highlights

Android 4.0, 4.0.1, 4.0.2

14


ICE_CREAM_SANDWICH


Android 3.2

13


HONEYCOMB_MR2


Android 3.1.x

12


HONEYCOMB_MR1


Platform Highlights

Android 3.0.x

11


HONEYCOMB


Platform Highlights

Android 2.3.4


Android 2.3.3

10


GINGERBREAD_MR1


Platform Highlights

Android 2.3.2

Android 2.3.1


Android 2.3

9


GINGERBREAD


Android 2.2.x

8


FROYO


Platform Highlights

Android 2.1.x

7


ECLAIR_MR1


Platform Highlights

Android 2.0.1

6


ECLAIR_0_1


Android 2.0

5


ECLAIR


Android 1.6

4


DONUT


Platform Highlights

Android 1.5

3


CUPCAKE


Platform Highlights

Android 1.1
2

BASE_1_1

Android 1.0 1

BASE