给你的 Android 应用标注版本 2015-05-26 / 3,338 次 / 快抢沙发 /

Android 应用的版本名称和版本代码的命名规范。android:minSdkVersion/android:targetSdkVersion/android:maxSdkVersion 的作用。

Versioning is a critical component of your application upgrade and maintenance strategy. Versioning is important because:
版本标注是你的应用升级和维护策略的关键部分。版本标注很重要,是因为:
Users need to have specific information about the application version that is installed on their devices and the upgrade versions available for installation.
用户需要知道安装到他们设备上的应用的明确的版本信息和可安装的升级版本。
Other applications — including other applications that you publish as a suite — need to query the system for your application’s version, to determine compatibility and identify dependencies.
其它应用-包括其它你作为套件发布的应用-需要向系统查询你应用的版本,用来检测兼容性的和识别依赖。
Services through which you will publish your application(s) may also need to query your application for its version, so that they can display the version to users. A publishing service may also need to check the application version to determine compatibility and establish upgrade/downgrade relationships.
应用发布服务同样需要查询你应用的版本,显示给用户。发布服务同样需要检测应用的版本,用来检测兼容性和建立升级/降级的关系。
The Android system does not use app version information to enforce restrictions on upgrades, downgrades, or compatibility of third-party apps. Instead, you (the developer) are responsible for enforcing version restrictions within your application or by informing users of the version restrictions and limitations. The Android system does, however, enforce system version compatibility as expressed by the minSdkVersion attribute in the manifest. This attribute allows an application to specify the minimum system API with which it is compatible. For more information see Specifying Minimum System API Version.
Android 系统不会用应用的版本信息来强制约束升级、降级或者第三方应用的兼容性。相反,作为开发者的你,应该对你应用的强制版本约束负责或者提醒用户你的版本约束和限制。Android 系统所做的系统版本兼容性,通过在 AndroidManifest.xml 文件中声明 minSdkVersion(最小的sdk版本),这个属性允许应用指定其兼容的最小的系统 API 版本。更多信息请参见 “指定最小系统 API 版本“。
Setting Application Version
应用版本的设置
To define the version information for your application, you set attributes in the application’s manifest file. Two attributes are available, and you should always define values for both of them:
为了定义你的应用版本信息,你需要在 AndroidManifest.xml 文件中设置属性。你需要同时定义这两个属性:
android:versionCode — An integer value that represents the version of the application code, relative to other versions.
The value is an integer so that other applications can programmatically evaluate it, for example to check an upgrade or downgrade relationship. You can set the value to any integer you want, however you should make sure that each successive release of your application uses a greater value. The system does not enforce this behavior, but increasing the value with successive releases is normative.
android:versionCode 表示应用相对于其它版本的版本代码,是一个整型值。这个整型值是为了让其它应用可以检测升降级的关系。这个值你可以设置成任意你想要的整型值,但是你需要保证每一个成功发布的应用采用一个更大的值。系统并不强制这种行为,但是成功发布版本的时候,增加这个值是一种规范的行为。
Typically, you would release the first version of your application with versionCode set to 1, then monotonically increase the value with each release, regardless whether the release constitutes a major or minor release. This means that the android:versionCode value does not necessarily have a strong resemblance to the application release version that is visible to the user (see android:versionName, below). Applications and publishing services should not display this version value to users.
通常情况下,你的应用发布第一个版本的时候,应该将 versionCode 设置成1,然后每一次发布采用单调递增的方式,无论是大小版本的发布。这个就意味着 android:versionCode 值没有必要与对于用户可见的应用发布版本看起来很像。(参见下面的 android:versionName)。应用和发布服务不应当显示这个版本值给用户。
android:versionName — A string value that represents the release version of the application code, as it should be shown to users.
The value is a string so that you can describe the application version as a .. string, or as any other type of absolute or relative version identifier.
As with android:versionCode, the system does not use this value for any internal purpose, other than to enable applications to display it to users. Publishing services may also extract the android:versionName value for display to users.
android:versionName – 表示应用发布版本的代码,是一个字符串值,这个值应当显示给用户。这个值是一个字符串,所以你可以采取 .. 格式,或者其它绝对或者相对的版本标识符。和 android:versionCode 一样,系统不会使用这个值来作为任何内部用途,仅仅让应用显示给用户。发布服务同样会提取 android:versionName 显示给用户。
You define both of these version attributes in the element of the manifest file or the Gradle build file. See Configuring Gradle Builds.
你可以在 AndroidManifest.xml 文件中 标签来定义两个版本属性,或者 Gradle Build 文件中定义。参见 配置 Gradle Builds
Here’s an example manifest that shows the android:versionCode and android:versionName attributes in the element.
下面是一个在 AndroidManifest.xml 文件中 标签中显示 android:versionCode 和 android:versionName 属性的例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.package.name"
      android:versionCode="2"
      android:versionName="1.1">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        ...
    </application>
</manifest>
In this example, note that android:versionCode value indicates that the current .apk contains the second release of the application code, which corresponds to a minor follow-on release, as shown by the android:versionName string.
在上面的例子中,注意到 android:versionCode 值显示当前 .apk 文件是第二个应用版本代码,android:versionName 值显示的是小版本发布。
The Android framework provides an API to let applications query the system for version information about your application. To obtain version information, applications use the getPackageInfo(java.lang.String, int) method of PackageManager.
Android 框架提供了能够查询你应用版本信息的 API。通过调用 PackageManager 类的 getPackageInfo(java.lang.String, int) 方法来获取版本信息。
Specifying Your Application’s System API Requirements
指定你的应用系统 API 要求
If your application requires a specific minimum version of the Android platform, or is designed only to support a certain range of Android platform versions, you can specify those version requirements as API Level identifiers in the application’s manifest file. Doing so ensures that your application can only be installed on devices that are running a compatible version of the Android system.
如果你的应用要求一个明确的最小的 Android 平台版本,或者只支持小范围的 Android 平台版本,你可以在应用的 AndroidManifest.xml 文件中通过 API Level 标识符指定这些版本要求。这样你的应用就只能被安装在兼容的 Andorid 系统版本上了。
To specify API Level requirements, add a element in the application’s manifest, with one or more of these attributes:
android:minSdkVersion — The minimum version of the Android platform on which the application will run, specified by the platform’s API Level identifier.
android:targetSdkVersion — Specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level.
android:maxSdkVersion — The maximum version of the Android platform on which the application is designed to run, specified by the platform’s API Level identifier. Important: Please read the documentation before using this attribute.
可以通过在 AndroidManifest.xml 文件中添加 uses-sdk 标签,来指定 API Level要求。有以下属性:
android:minSdkVersion — 应用运行的最小的 Android 平台版本,通过平台对应的 API Level 标识符来指定。
android:targetSdkVersion — 指定设计应用对应的 API Level。在某些情况下,此属性允许应用使用 manifest 标签或者目标 API Level 定义的内容,而不是被限制只能使用最小的 API Level 中定义的内容。
android:maxSdkVersion — 应用能够运行的最大的 Android 平台版本,通过平台对应的 API Level 标识符来指定。重要:在使用这个属性的之前,请阅读 uses-sdk 文档。
When preparing to install your application, the system checks the value of this attribute and compares it to the system version. If the android:minSdkVersion value is greater than the system version, the system aborts the installation of the application. Similarly, the system installs your application only if its android:maxSdkVersion is compatible with the platform version.
当准备安装你的应用的时候,系统会检查相关属性值并且和系统版本对比。如果 android:minSdkVersion 值比系统版本要大,系统会中止应用的安装。类似的,如果android:maxSdkVersion 兼容平台版本的话,系统才会允许安装。

If you do not specify these attributes in your manifest, the system assumes that your application is compatible with all platform versions, with no maximum API Level.
To specify a minimum platform version for your application, add a uses-sdk element as a child of manifest, then define the android:minSdkVersion as an attribute.
For more information, see the uses-sdk manifest element documentation and the API Levels document. For Gradle build settings, see Configuring Gradle Builds.
如果你没有在 AndroidManifest.xml 文件中指定这些属性的话,系统会假设你的应用兼容所有平台版本,没有最大的 API Level。
可以通过添加 manifest 的子标签 uses-sdk ,然后定义 android:minSdkVersion 属性来指定最小的平台版本。
更多信息,请参见 uses-sdk manifest 标签文档和 API Levels 文档。 Gradle build 设置,请参见 配置 Gradle Builds
说明:以上英文内容均来自 Android 官网,中文翻译部分纯属个人学习 Android 和英语之用,由于个人英语水平有限,难免会出现偏差甚至错误,请谨慎参考!
打赏
本博客所有文章如无特别注明均为原创。复制或转载请以超链接形式注明转自ifeegoo,原文地址《给你的 Android 应用标注版本
上一篇: « 下一篇: »
暂无相关文章
Copyright © ifeegoo Time is limited, less is more! / 粤ICP备15109713号 / Theme by Hang & Ben / WordPress / 知识共享许可协议