| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 1 | page.title=Versioning Your Applications |
| 2 | @jd:body |
| 3 | |
| 4 | <div id="qv-wrapper"> |
| 5 | <div id="qv"> |
| 6 | |
| 7 | <h2>Versioning quickview</h2> |
| 8 | |
| 9 | <ul> |
| 10 | <li>Your application <em>must</em> be versioned</a></li> |
| 11 | <li>You set the version in the application's manifest file</li> |
| 12 | <li>How you version your applications affects how users upgrade </li> |
| 13 | <li>Determine your versioning strategy early in the development process, including considerations for future releases.</li> |
| 14 | </ul> |
| 15 | |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 16 | <h2>In this document</h2> |
| 17 | |
| 18 | <ol> |
| 19 | <li><a href="#appversion">Setting Application Version</a></li> |
| 20 | <li><a href="#minsdkversion">Specifying Minimum System API Version</a> |
| 21 | </ol> |
| 22 | |
| 23 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 24 | <h2>See also</h2> |
| 25 | |
| 26 | <ol> |
| 27 | <li><a href="{@docRoot}guide/publishing/preparing.html">Preparing to Publish Your Application</a></li> |
| 28 | <li><a href="{@docRoot}guide/publishing/publishing.html#market">Publishing On Android Market</a></li> |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 29 | <li><a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml File</a></li> |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 30 | </ol> |
| 31 | |
| 32 | </div> |
| 33 | </div> |
| 34 | |
| 35 | <p>Versioning is a critical component of your application upgrade/maintenance |
| 36 | strategy. </p> |
| 37 | |
| 38 | <ul> |
| 39 | <li>Users need to have specific information about the application version that |
| 40 | is installed on their devices and the upgrade versions available for |
| 41 | installation. </li> |
| 42 | <li>Other applications — including other applications that you publish as |
| 43 | a suite — need to query the system for your application's version, to |
| 44 | determine compatibility and identify dependencies.</li> |
| 45 | <li>Services through which you will publish your application(s) may also need to |
| 46 | query your application for its version, so that they can display the version to |
| 47 | users. A publishing service may also need to check the application version to |
| 48 | determine compatibility and establish upgrade/downgrade relationships.</li> |
| 49 | </ul> |
| 50 | |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 51 | <p>The Android system itself <em>does not ever</em> check the application version |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 52 | information for an application, such as to enforce restrictions on upgrades, |
| 53 | compatibility, and so on. Instead, only users or applications themselves are |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 54 | responsible for enforcing any version restrictions for applications themselves. </p> |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 55 | |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 56 | <p>The Android system <em>does</em> check any system version compatibility expressed |
| 57 | by an application in its manifest, in the <code>minSdkVersion</code> attribute. This |
| 58 | allows an application to specify the minimum system API with which is compatible. |
| 59 | For more information see <a href="#minsdkversion">Specifying Minimum System API Version</a>. |
| 60 | |
| 61 | <h2 id="appversioning">Setting Application Version</h2> |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 62 | <p>To define the version information for your application, you set attributes in |
| 63 | the application's manifest file. Two attributes are available, and you should |
| 64 | always define values for both of them: </p> |
| 65 | |
| 66 | <ul> |
| 67 | <li><code>android:versionCode</code> — An integer value that represents |
| 68 | the version of the application code, relative to other versions. |
| 69 | |
| 70 | <p>The value is an integer so that other applications can programatically |
| 71 | evaluate it, for example to check an upgrade or downgrade relationship. You can |
| 72 | set the value to any integer you want, however you should make sure that each |
| 73 | successive release of your application uses a greater value. The system does not |
| 74 | enforce this behavior, but increasing the value with successive releases is |
| 75 | normative. </p> |
| 76 | |
| 77 | <p>Typically, you would release the first version of your application with |
| 78 | versionCode set to 1, then monotonically increase the value with each release, |
| 79 | regardless whether the release constitutes a major or minor release. This means |
| 80 | that the <code>android:versionCode</code> value does not necessarily have a |
| 81 | strong resemblence to the application release version that is visible to the |
| 82 | user (see <code>android:versionName</code>, below). Applications and publishing |
| 83 | services should not display this version value to users.</p> |
| 84 | </li> |
| 85 | <li><code>android:versionName</code> — A string value that represents the |
| 86 | release version of the application code, as it should be shown to users. |
| 87 | <p>The value is a string so that you can describe the application version as a |
| 88 | <major>.<minor>.<point> string, or as any other type of |
| 89 | absolute or relative version identifier. </p> |
| 90 | |
| 91 | <p>As with <code>android:versionCode</code>, the system does not use this value |
| 92 | for any internal purpose, other than to enable applications to display it to |
| 93 | users. Publishing services may also extract the <code>android:versionName</code> |
| 94 | value for display to users.</p> |
| 95 | </li> |
| 96 | </ul> |
| 97 | |
| 98 | <p>You define both of these version attributes in the |
| 99 | <code><manifest></code> element of the manifest file. </p> |
| 100 | |
| 101 | <p>Here's an example manifest that shows the <code>android:versionCode</code> |
| 102 | and <code>android:versionName</code> attributes in the |
| 103 | <code><manifest></code> element. </p> |
| 104 | |
| 105 | <pre> |
| 106 | <?xml version="1.0" encoding="utf-8"?> |
| 107 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
| 108 | package="com.example.package.name" |
| 109 | android:versionCode="2" |
| 110 | android:versionName="1.1"> |
| 111 | <application android:icon="@drawable/icon" android:label="@string/app_name"> |
| 112 | ... |
| 113 | </application> |
| 114 | </manifest> |
| 115 | </pre> |
| 116 | |
| 117 | <p>In this example, note that <code>android:versionCode</code> value indicates |
| 118 | that the current .apk contains the second release of the application code, which |
| 119 | corresponds to a minor follow-on release, as shown by the |
| 120 | <code>android:codeName</code> string. </p> |
| 121 | |
| 122 | <p>The Android framework provides an API to let applications query the system |
| 123 | for version information about your application. To obtain version information, |
| 124 | applications use the |
| 125 | {@link android.content.pm.PackageManager#getPackageInfo(java.lang.String, int)} |
| 126 | method of {@link android.content.pm.PackageManager PackageManager}. </p> |
| 127 | |
| The Android Open Source Project | 3001a03 | 2009-02-19 10:57:31 -0800 | [diff] [blame] | 128 | <h2 id="minsdkversion">Specifying Minimum System API Version</h2> |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 129 | |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 130 | <p>If your application requires a specific minimum version of the Android |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 131 | platform, you can specify that version as an API Level identifier |
| 132 | in the application's manifest file. Doing so ensures that your |
| 133 | application can only be installed on devices that |
| 134 | are running a compatible version of the Android system. </p> |
| 135 | |
| 136 | <p>To specify the minimum system version in the manifest, use this attribute: </p> |
| The Android Open Source Project | f013e1a | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 137 | |
| 138 | <ul> |
| 139 | <li><code>android:minSdkVersion</code> — An integer value corresponding to |
| 140 | the code version of the Android platform. |
| 141 | <p>When preparing to install an application, the system checks the value of this |
| 142 | attribute and compares it to the system version. If the |
| 143 | <code>android:minSdkVersion</code> value is greater than the system version, the |
| 144 | system aborts the installation of the application. </p> |
| 145 | |
| 146 | <p>If you do not specify this attribute in your manifest, the system assumes |
| 147 | that your application is compatible with all platform versions.</p></li> |
| 148 | </ul> |
| 149 | |
| 150 | <p>To specify a minimum platform version for your application, add a |
| 151 | <code><uses-sdk></code> element as a child of |
| 152 | <code><manifest></code>, then define the |
| The Android Open Source Project | d24b818 | 2009-02-10 15:44:00 -0800 | [diff] [blame] | 153 | <code>android:minSdkVersion</code> as an attribute. </p> |
| 154 | |
| The Android Open Source Project | 3001a03 | 2009-02-19 10:57:31 -0800 | [diff] [blame] | 155 | <p>For more information, also see the <a href="{@docRoot}sdk/android-1.1.html">Android System Image 1.1 Version Notes</a>.</p> |