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
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
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 tominSdkVersion
).
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参考相应平台的版本中描述。
为了保持与每个版本的Android沿着你的应用程序,您应该增加这个属性来匹配最新的API级别的值,然后在相应的平台版本全面测试您的应用程序。
android:maxSdkVersion
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
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 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:
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级别?