1page.title=Multiple APK Support 2 3@jd:body 4 5<div id="qv-wrapper"> 6<div id="qv"> 7 8 <h2>Quickview</h2> 9 <ul> 10 <li>Simultaneously publish different APKs for different 11device configurations</li> 12 <li>You should publish multiple APKs only when it's not possible to 13support all desired devices with a single APK</li> 14 </ul> 15 16 <h2>In this document</h2> 17<ol> 18 <li><a href="#Concepts">Publishing Concepts</a> 19 <ol> 20 <li><a href="#Active">Active APKs</a></li> 21 <li><a href="#SimpleAndAdvanced">Simple mode and advanced mode</a></li> 22 </ol> 23 </li> 24 <li><a href="#HowItWorks">How Multiple APKs Work</a> 25 <ol> 26 <li><a href="#SupportedFilters">Supported filters</a></li> 27 <li><a href="#Rules">Rules for multiple APKs</a></li> 28 </ol> 29 </li> 30 <li><a href="#CreatingApks">Creating Multiple APKs</a> 31 <ol> 32 <li><a href="#VersionCodes">Assigning version codes</a></li> 33 </ol> 34 </li> 35 <li><a href="#SingleAPK">Using a Single APK Instead</a> 36 <ol> 37 <li><a href="#TextureOptions">Supporting multiple GL textures</a></li> 38 <li><a href="#ScreenOptions">Supporting multiple screens</a></li> 39 <li><a href="#ApiLevelOptions">Supporting multiple API levels</a></li> 40 <li><a href="#CpuArchOptions">Supporting multiple CPU architectures</a></li> 41 </ol> 42 </li> 43</ol> 44 45 <h2>See also</h2> 46<ol> 47 <li><a href="{@docRoot}google/play/expansion-files.html">APK Expansion Files</a></li> 48 <li><a href="{@docRoot}google/play/filters.html">Filters on Google Play</a></li> 49 <li><a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple Screens</a></li> 50 <li><a href="{@docRoot}tools/support-library/index.html">Support Library</a></li> 51 <li><a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#ApiLevels">Android API Levels</a></li> 52</ol> 53 54</div> 55</div> 56 57<p>Multiple APK support is a feature on Google Play that allows you to publish different APKs 58for your application that are each targeted to different device configurations. Each APK is a 59complete and independent version of your application, but they share the same application listing on 60Google Play and must share the same package name and be signed with the same release key. This 61feature is useful for cases in which your application cannot reach all desired devices with a single 62APK.</p> 63 64<p>Android-powered devices may differ in several ways and it's important 65to the success of your application that you make it available to as many devices as possible. 66Android applications usually run on most compatible devices with a single APK, by supplying 67alternative resources for different configurations (for example, different layouts for different 68screen sizes) and the Android system selects the appropriate resources for the device at runtime. In 69a few cases, however, a single APK is unable to support all device configurations, because 70alternative resources make the APK file too big (greater than 50MB) or other technical challenges 71prevent a single APK from working on all devices.</p> 72 73<p>Although <strong>we encourage you to develop and publish a single APK</strong> that supports as 74many device configurations as possible, doing so is sometimes not possible. To help 75you publish your application for as many devices as possible, Google Play allows you to 76publish multiple APKs under the same application listing. Google Play then supplies each APK to 77the appropriate devices based on configuration support you've declared in the manifest file of each 78APK. </p> 79 80<p>By publishing your application with multiple APKs, you can:</p> 81 82<ul> 83 <li>Support different OpenGL texture compression formats with each APK.</li> 84 <li>Support different screen sizes and densities with each APK.</li> 85 <li>Support different device feature sets with each APK.</li> 86 <li>Support different platform versions with each APK.</li> 87 <li>Support different CPU architectures with each APK (such as for ARM, x86, and MIPS, when your 88 app uses the <a href="{@docRoot}tools/sdk/ndk/index.html">Android NDK</a>).</li> 89</ul> 90 91<p>Currently, these are the only device characteristics that Google Play supports for publishing 92multiple APKs as the same application.</p> 93 94<p class="note"><strong>Note:</strong> You should generally use multiple APKs to support 95different device configurations <strong>only when your APK is too large</strong> (greater than 9650MB) due to the alternative resources needed for different device configurations. 97Using a single APK to support different configurations is always the best practice, 98because it makes the path for application updates simple and clear for users (and also makes 99your life simpler by avoiding development and publishing complexity). Read the section below about 100<a href="#SingleAPK">Using a Single APK Instead</a> to 101consider your options before publishing multiple APKs.</p> 102 103 104<h2 id="Concepts">Publishing Concepts</h2> 105 106<p>Before you start publishing multiple APKs on Google Play, you must understand a few 107concepts regarding how the Google Play Developer Console works.</p> 108 109<h3 id="Active">Active APKs</h3> 110 111<div class="sidebox-wrapper"> 112<div class="sidebox"> 113 <h4>The difference between "Publish" and "Save"</h4> 114 <p>When editing your application, there are two buttons on the top-right side of the page. The 115first button is either <strong>Publish</strong> or <strong>Unpublish</strong> and the second 116button is always <strong>Save</strong> (but its behavior changes).</p> 117 <p>When your application is new or you have unpublished it from Google Play, the first 118button says <strong>Publish</strong>. Clicking it will publish any APKs listed as 119Active, making them available on Google Play. Also while your application is new 120or unpublished, clicking <strong>Save</strong> will save any changes you've made, such 121as information added to the Product details and APKs you've uploaded, but nothing is made visible on 122Google Play—this allows you to save your changes and sign out of the Developer Console before 123deciding to publish.</p> 124 <p>Once you've published your application, the first button changes to 125<strong>Unpublish</strong>. Clicking it in this state unpublishes your application so that none 126of the APKs are available on Google Play. Also while published, the behavior of the 127<strong>Save</strong> button is different. In this state, clicking <strong>Save</strong> not 128only saves all your changes, but also publishes them to Google Play. For example, if you've 129already published your application and then make changes to your product details or activate new 130APKs, clicking <strong>Save</strong> makes all those changes live on Google Play.</p> 131</div> 132</div> 133 134 135<p>Before you can publish your application (whether publishing one or multiple APKs), you 136must "activate" your APK(s) from the <strong>APK files</strong> tab. When you activate an APK, it 137moves into the list of <em>Active</em> APKs. This list allows you to preview which APK(s) 138you're about to publish.</p> 139 140<p>If there are no errors, any "active" APK will be published to 141Google Play when you click the <strong>Publish</strong> button (if the application is 142unpublished) or when you click the <strong>Save</strong> button (if the application is 143already published).</p> 144 145 146<h3 id="SimpleAndAdvanced">Simple mode and advanced mode</h3> 147 148<p>The Google Play Developer Console provides two modes for managing the APKs associated with 149your application: <em>simple mode</em> and <em>advanced mode</em>. You can switch between these by 150clicking the 151link at the top-right corner of the <strong>APK files</strong> tab.</p> 152 153<p>Simple mode is the traditional way to publish an application, using one APK at a time. In 154simple mode, only one APK can be activated at a time. If you upload a new APK to update 155the application, clicking "Activate" on the new APK deactivates the currently 156active APK (you must then click <strong>Save</strong> to publish the new APK).</p> 157 158<p>Advanced mode allows you to activate and publish multiple APKs that are each designed for a 159specific set of device configurations. However, there are several rules based on the manifest 160declarations in each APK that determine whether you're allowed to activate each APK along with 161others. When you activate an APK and it violates one of the rules, you will receive an error or 162warning message. If it's an error, you cannot publish until you resolve the problem; if it's a 163warning, you can publish the activated APKs, but there might be unintended consequences as to 164whether your application is available for different devices. These rules are discussed more 165below.</p> 166 167 168<h2 id="HowItWorks">How Multiple APKs Work</h2> 169 170<p>The concept for using multiple APKs on Google Play is that you have just one entry in 171Google Play for your application, but different devices might download a different APK. This 172means that:</p> 173 174<ul> 175 <li>You maintain only one set of product details (app description, icons, screenshots, etc.). 176This also means you <em>cannot</em> charge a different price for different APKs.</li> 177 <li>All users see only one version of your application on Google Play, so they are not 178confused by different versions you may have published that are "for tablets" or 179"for phones."</li> 180 <li>All user reviews are applied to the same application listing, even though users on different 181devices may have different APKs.</li> 182 <li>If you publish different APKs for different versions of Android (for different API levels), 183then when a user's device receives a system update that qualifies them for a different APK you've 184published, Google Play updates the user's application to the APK designed for the higher version 185of Android. Any system data associated with the application is retained (the same as with normal 186application updates when using a single APK).</li> 187</ul> 188 189<p>To publish multiple APKs for the same application, you must enable <strong>Advanced mode</strong> 190in your application's <strong>APK files</strong> tab (as discussed in the previous section). Once 191in advanced mode, you can upload, activate, then publish multiple APKs for the same application. The 192following sections describe more about how it works.</p> 193 194 195<h3 id="SupportedFilters">Supported filters</h3> 196 197<p>Which devices receive each APK is determined by <a 198href="{@docRoot}google/play/filters.html">Google Play filters</a> that are specified by 199elements in the manifest file of each APK. However, Google Play allows you to publish multiple 200APKs only when each APK uses filters to support a variation of the following 201device characteristics:</p> 202 203<ul> 204 <li><strong>OpenGL texture compression formats</strong> 205 <p>This is based on your manifest file's <a 206href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html">{@code 207<supports-gl-texture>}</a> element(s).</p> 208 <p>For example, when developing a game that uses OpenGL ES, you can provide one APK for 209devices that support ATI texture compression and a separate APK for devices 210that support PowerVR compression (among many others).</p> 211 <br/> 212 </li> 213 214 <li><strong>Screen size (and, optionally, screen density)</strong> 215 <p>This is based on your manifest file's <a 216href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code 217<supports-screens>}</a> <em>or</em> <a 218href="{@docRoot}guide/topics/manifest/compatible-screens-element.html">{@code 219<compatible-screens>}</a> element. You should never use both elements and you should use only 220<a href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code 221<supports-screens>}</a> when possible.</p> 222 <p>For example, you can provide one APK that supports small and normal size screens and another 223APK that supports large and xlarge screens.</p> 224 225 <p class="note"><strong>Note:</strong> The Android system provides strong support for 226applications to support all screen configurations with a single APK. You should avoid creating 227multiple APKs to support different screens unless absolutely necessary and instead follow the guide 228to <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple 229Screens</a> so that your application is flexible and can adapt to all screen configurations 230with a single APK.</p> 231 <p class="caution"><strong>Caution:</strong> By default, all screen size attributes in the <a 232href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code 233<supports-screens>}</a> element are "true" if you do not declare them otherwise. However, 234because the {@code android:xlargeScreens} attribute was added in Android 2.3 (API level 2359), Google Play will assume that it is "false" if your application does not set either <a 236href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 237android:minSdkVersion}</a> or <a 238href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code 239android:targetSdkVersion}</a> to "9" or higher.</p> 240 <p class="caution"><strong>Caution:</strong> You should not combine both <a 241href="{@docRoot}guide/topics/manifest/supports-screens-element.html">{@code 242<supports-screens>}</a> and <a 243href="{@docRoot}guide/topics/manifest/compatible-screens-element.html">{@code 244<compatible-screens>}</a> elements in your manifest file. Using both increases the chances 245that you'll introduce an error due to conflicts between them. For help deciding which to use, read 246<a href="{@docRoot}guide/practices/screens-distribution.html">Distributing to Specific Screens</a>. 247If you can't avoid using both, be aware that for any conflicts in agreement between a given size, 248"false" will win.</p> 249 <br/> 250 </li> 251 252 <li><strong>Device feature sets</strong> 253 <p>This is based on your manifest file's <a 254href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code <uses-feature>}</a> 255element(s).</p> 256 <p>For example, you can provide one APK for devices that support multitouch and another 257APK for devices that do not support multitouch. See 258<a href="{@docRoot}guide/topics/manifest/uses-feature-element.html#features-reference">Features 259Reference</a> for a list of features supported by the platform.</p> 260 <br/> 261 </li> 262 263 <li><strong>API level</strong> 264 <p>This is based on your manifest file's <a 265href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">{@code <uses-sdk>}</a> element. 266You 267can use both the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 268android:minSdkVersion}</a> and <a 269href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#max">{@code android:maxSdkVersion}</a> 270attributes to specify support for different API levels.</p> 271 <p>For example, you can publish your application with one APK that supports API levels 4 - 7 272(Android 1.6 - 2.1)—using only APIs available since API level 4 or lower—and another 273APK that supports API levels 8 and above (Android 2.2+)—using APIs available since API level 8 274or lower.</p> 275 <div class="note"> 276 <p><strong>Note:</strong></p> 277 <ul> 278 <li>If you use this characteristic as the factor to distinguish multiple APKs, then the APK 279with a higher <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 280android:minSdkVersion}</a> value must have a higher <a 281href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code android:versionCode}</a> 282value. This is also true if two APKs overlap their device support based on a different supported 283filter. This ensures that when a device receives a system update, Google Play can offer the user 284an update for your application (because updates are based on an increase in the app version code). 285This requirement is described further in the section below about <a href="#Rules">Rules for 286multiple APKs</a>.</li> 287 <li>You should avoid using <a 288href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#max">{@code 289android:maxSdkVersion}</a> in general, because as long as you've properly developed your 290application with public APIs, it is always compatible with future versions of Android. If you want 291to publish a different APK for higher API levels, you still do not need to specify the 292maximum version, because if the <a 293href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code 294android:minSdkVersion}</a> is {@code "4"} in one APK and {@code "8"} in another, devices that 295support API level 8 or higher will always receive the second APK (because it's version code is 296higher, as per the previous note).</li> 297 </ul> 298 </div> 299 </li> 300 301 <li><strong>CPU architecture (ABI)</strong> 302 <p>This is based on the native libraries included in each APK (which are 303 determined by the architectures you declare in the {@code Application.mk} 304 file) when using the Android NDK.</p></li> 305</ul> 306 307<p>Other manifest elements that enable <a 308href="{@docRoot}google/play/filters.html">Google Play filters</a>—but are not 309listed above—are still applied for each APK as usual. However, Google Play does not allow 310you to publish separate APKs based on variations of those device characteristics. Thus, you cannot 311publish multiple APKs if the above listed filters are the same for each APK (but the APKs differ 312based on other characteristics in the manifest or APK). For 313example, you cannot provide different APKs that differ purely on the <a 314href="{@docRoot}guide/topics/manifest/uses-configuration-element.html">{@code 315<uses-configuration>}</a> characteristics.</p> 316 317 318 319<h3 id="Rules">Rules for multiple APKs</h3> 320 321<p>Before you enable advanced mode to publish multiple APKs for your application, you need to 322understand the following rules that define how publishing multiple APKs works:</p> 323 324<ul> 325 <li>All APKs you publish for the same application <strong>must have the same package 326name and be signed with the same certificate key</strong>.</li> 327 328 <li>Each APK <strong>must have a different version code</strong>, specified by the 329<a href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code 330android:versionCode}</a> attribute.</li> 331 332 <li>Each APK <strong>must not exactly match the configuration support of another APK</strong>. 333 <p>That is, each APK must declare slightly different support for at least one of 334the <a href="#SupportedFilters">supported Google Play filters</a> (listed above).</p> 335 <p>Usually, you will differentiate your APKs based on a specific characteristic (such as the 336supported texture compression formats), and thus, each APK will declare support for different 337devices. However, it's OK to publish multiple APKs that overlap their support slightly. When two 338APKs do overlap (they support some of the same device configurations), a device that falls within 339that overlap range will receive the APK with a higher version code (defined by <a 340href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code 341android:versionCode}</a>).</p></li> 342 343 <li>You cannot activate a new APK that has a version code lower than that of the APK it's 344replacing. For example, say you have an active APK for screen sizes small - normal with version code 3450400, then try to replace it with an APK for the same screen sizes with version code 0300. This 346raises an error, because it means users of the previous APK will not be able to update the 347application.</li> 348 349 <li>An APK that requires a <strong>higher API level</strong> must have a <strong>higher 350version code</strong>. 351 <p>This is true only when either: the APKs differ based <em>only</em> on the 352supported API levels (no other <a href="#SupportedFilters">supported filters</a> 353distinguish the APKs from each other) <em>or</em> when the APKs do use another supported filter, but 354there is an overlap between the APKs within that filter.</p> 355 <p>This is important because a user's device receives an application update from 356Google Play only if the version code for the APK on Google Play is higher than the version 357code of the APK currently on the device. This ensures that if a device receives a system update that 358then qualifies it to install the APK for higher API levels, the device receives an application 359update because the version code increases.</p> 360<p class="note"><strong>Note:</strong> The size of the version code increase is irrelevant; it 361simply needs to be larger in the version that supports higher API levels.</p> 362 <p>Here are some examples:</p> 363 <ul> 364 <li>If an APK you've uploaded for API levels 4 and above (Android 1.6+) has a version code of 365{@code 0400}, then an APK for API levels 8 and above (Android 2.2+) must be {@code 0401} or 366greater. In this case, the API level is the only supported filter used, so the version codes 367<strong>must increase</strong> in correlation with the API level support for each APK, so that users 368get an update when they receive a system update.</li> 369 <li>If you have one APK that's for API level 4 (and above) <em>and</em> small - 370large screens, and another APK for API level 8 (and above) <em>and</em> large - xlarge screens, then 371the version codes <strong>must increase</strong> in correlation with the API levels. 372In this case, the API level filter is used to 373distinguish each APK, but so is the screen size. Because the screen sizes overlap (both APKs 374support large screens), the version codes must still be in order. This ensures that a large screen 375device that receives a system update to API level 8 will receive an update for the second 376APK.</li> 377 <li>If you have one APK that's for API level 4 (and above) <em>and</em> small - 378normal screens, and another APK for API level 8 (and above) <em>and</em> large - xlarge 379screens, then the version codes <strong>do not need to increase</strong> in correlation with the API 380levels. Because there is no overlap within the screen size filter, there are no devices that 381could potentially move between these two APKs, so there's no need for the version codes to 382increase from the lower API level to the higher API level.</li> 383 <li>If you have one APK that's for API level 4 (and above) <em>and</em> ARMv7 CPUs, 384and another APK for API level 8 (and above) <em>and</em> ARMv5TE CPUs, 385then the version codes <strong>must increase</strong> in correlation with the API levels. 386In this case, the API level filter is used to 387distinguish each APK, but so is the CPU architecture. Because an APK with ARMv5TE libraries is 388compatible with devices that have an ARMv7 CPU, the APKs overlap on this characteristic. 389As such, the version code for the APK that supports API level 8 and above must be higher. 390This ensures that a device with an ARMv7 CPU that receives a system update to API level 8 391will receive an update for the second APK that's designed for API level 8. 392However, because this kind of update results in the ARMv7 device using an APK that's not 393fully optimized for that device's CPU, you should provide an 394APK for both the ARMv5TE and the ARMv7 architecture at each API level in order to optimize 395the app performance on each CPU. 396<strong>Note:</strong> This applies <em>only</em> when comparing APKs with the ARMv5TE and 397ARMv7 libraries, and not when comparing other native libraries.</li> 398 </ul> 399 </li> 400 401</ul> 402 403<p>Failure to abide by the above rules results in an error on the Google Play Developer Console 404when you activate your APKs—you will be unable to publish your application until you 405resolve the error.</p> 406 407<p>There are other conflicts that might occur when you activate your APKs, but which will result 408in warnings rather than errors. Warnings can be caused by the following:</p> 409 410<ul> 411 <li>When you modify an APK to "shrink" the support for a device's characteristics and no other 412APKs support the devices that then fall outside the supported range. For example, if an APK 413currently supports small and normal size screens and you change it to support only small screens, 414then you have shrunk the pool of supported devices and some devices will no longer see your 415application on Google Play. You can resolve this by adding another APK that supports normal size 416screens so that all previously-supported devices are still supported.</li> 417 418 <li>When there are "overlaps" between two or more APKs. For example, if an APK supports screen 419sizes small, normal, and large, while another APK supports sizes large and xlarge, there is an 420overlap, because both APKs support large screens. If you do not resolve this, then devices that 421qualify for both APKs (large screen devices in the example) will receive whichever APK has the 422highest version code. 423 <p class="note"><strong>Note:</strong> If you're creating separate APKs for different CPU 424 architectures, be aware that an APK for ARMv5TE will overlap with an APK for ARMv7. That is, 425 an APK designed for ARMv5TE is compatible with an ARMv7 device, 426but the reverse is not true (an APK with only the ARMv7 libraries is 427<em>not</em> compatible with an ARMv5TE device).</li> 428</ul> 429 430<p>When such conflicts occur, you will see a warning message, but you can still publish your 431application.</p> 432 433 434 435<h2 id="CreatingApks">Creating Multiple APKs</h2> 436 437<p>Once you decide to publish multiple APKs, you probably need to create separate 438Android projects for each APK you intend to publish so that you can appropriately develop them 439separately. You can do this by simply duplicating your existing project and give it a new name. 440(Alternatively, you might use a build system that can output different resources—such 441as textures—based on the build configuration.)</p> 442 443<p class="note"><strong>Tip:</strong> One way to avoid duplicating large portions of your 444application code is to use a <a 445href="{@docRoot}tools/projects/index.html#LibraryProjects">library project</a>. A library 446project holds shared code and resources, which you can include in your actual application 447projects.</p> 448 449<p>When creating multiple projects for the same application, it's a good practice to identify each 450one with a name that indicates the device restrictions to be placed on the APK, so you can 451easily identify them. For example, "HelloWorld_8" might be a good name for an 452application designed for API level 8 and above.</p> 453 454<p class="note"><strong>Note:</strong> All APKs you publish for the same application 455<strong>must have the same package name and be signed with the same certificate key</strong>. Be 456sure you also understand each of the <a href="#Rules">Rules for multiple APKs</a>.</p> 457 458 459<h3 id="VersionCodes">Assigning version codes</h3> 460 461<p>Each APK for the same application <strong>must have a unique version code</strong>, specified by 462the <a href="{@docRoot}guide/topics/manifest/manifest-element.html#vcode">{@code 463android:versionCode}</a> attribute. You must be careful about assigning version codes when 464publishing multiple APKs, because they must each be different, but in some 465cases, must or should be defined in a specific order, based on the configurations that each APK 466supports.</p> 467 468<h4>Ordering version codes</h4> 469 470<p>An APK that requires a higher API level must usually have a higher version code. For example, if 471you create two APKs to support different API levels, the APK for the higher API levels must have the 472higher version code. This ensures that if a device receives a system update that then qualifies it 473to install the APK for higher API levels, the user receives a notification to update the app. For 474more information about how this requirement applies, see the section above about <a 475href="#Rules">Rules for multiple APKs</a>.</p> 476 477<p>You should also consider how the order of version codes might affect which APK your users 478receive either due to overlap between coverage of different APKs or future changes you might make to 479your APKs.</p> 480 481<p>For example, if you have different APKs based on screen size, such as one for small - normal and 482one for large - xlarge, but foresee a time when you will change the APKs to be one for small and one 483for normal - xlarge, then you should make the version code for the large - xlarge APK be higher. 484That way, a normal size device will receive the appropriate update when you make the change, because 485the version code increases from the existing APK to the new APK that now supports the device. </p> 486 487<p>Also, when creating multiple APKs that differ based on support for different OpenGL texture 488compression formats, be aware that many devices support multiple formats. Because a device 489receives the APK with the highest version code when there is an overlap in coverage between two 490APKs, you should order the version codes among your APKs so that the APK with the 491preferred compression format has the highest version code. For example, you might want to perform 492separate builds for your app using PVRTC, ATITC, and ETC1 compression formats. If you prefer these 493formats in this exact order, then the APK that uses PVRTC should have the highest version code, the 494APK that uses ATITC has a lower version code, and the version with ETC1 has the lowest. Thus, if a 495device supports both PVRTC and ETC1, it receives the APK with PVRTC, because it has the highest 496version code.</p> 497 498 499<h4>Using a version code scheme</h4> 500 501<p>In order to allow different APKs to update their version codes independent of others (for 502example, when you fix a bug in only one APK, so don't need to update all APKs), you should use a 503scheme for your version codes that 504provides sufficient room between each APK so that you can increase the code in one without requiring 505an increase in others. You should also include your actual version name in the code (that is, the 506user visible version assigned to <a 507href="{@docRoot}guide/topics/manifest/manifest-element.html#vname">{@code android:versionName}</a>), 508so that it's easy for you to associate the version code and version name.</p> 509 510<p class="note"><strong>Note:</strong> When you increase the version code for an APK, Google 511Play will prompt users of the previous version to update the application. Thus, to avoid 512unnecessary updates, you should not increase the version code for APKs that do not actually 513include changes.</p> 514 515<p>We suggest using a version code with at least 7 digits: integers that represent 516the supported configurations are in the higher order bits, and the version name (from <a 517href="{@docRoot}guide/topics/manifest/manifest-element.html#vname">{@code 518android:versionName}</a>) is in the lower order bits. For example, when the application version 519name is 3.1.0, version codes for an API level 4 520APK and an API level 11 APK would be something like 0400310 and 1100310, respectively. The first 521two digits are reserved for the API Level (4 and 11, respectively), the middle two digits are for 522either screen sizes or GL texture formats (not used in these examples), and the last three digits 523are for the application's version name (3.1.0). Figure 1 shows two examples that split based on both 524the platform version (API Level) and screen size.</p> 525 526<img src="{@docRoot}images/market/version-codes.png" alt="" /> 527<p class="img-caption"><strong>Figure 1.</strong> A suggested scheme for your version codes, 528using the first two digits for the API Level, the second and third digits for the minimum and 529maximum screen size (1 - 4 indicating each of the four sizes) or to denote the texture formats 530and the last three digits for the app version.</p> 531 532<p>This scheme for version codes is just a suggestion for how you should establish a 533pattern that is scalable as your application evolves. In particular, this scheme doesn't 534demonstrate a solution for identifying different texture compression formats. One option might be 535to define your own table that specifies a different integer to each of the different 536compression formats your application supports (for example, 1 might correspond to ETC1 and 2 is 537ATITC, and so on).</p> 538 539<p>You can use any scheme you want, but you should carefully consider how future versions of your 540application will need to increase their version codes and how devices can receive updates when 541either the device configuration changes (for example, due to a system update) or when you modify the 542configuration support for one or several of the APKs.</p> 543 544 545 546 547<h2 id="SingleAPK">Using a Single APK Instead</h2> 548 549<p><strong>Creating multiple APKs for your application is not the normal procedure</strong> for 550publishing an application on Google Play. In most cases, you should be able to publish your 551application to most users with a single APK and we encourage that you do so. When you encounter 552a situation in which using a single APK becomes difficult, you should carefully consider all your 553options before deciding to publish multiple APKs.</p> 554 555<p>First of all, there are a few key benefits to developing a single APK that supports all 556devices:</p> 557 558<ul> 559 <li><strong>Publishing and managing your application is easier.</strong> 560 <p>With only one APK to worry about at any given time, you're less likely to become confused by 561which APK is what. You also don't have to keep track of multiple version codes for each 562APK—by using only one APK, you can simply increase the version code with each release and 563be done.</p> </li> 564 <li><strong>You need to manage only a single code base.</strong> 565 <p>Although you can use a <a 566href="{@docRoot}tools/projects/index.html#LibraryProjects">library project</a> 567to share code between multiple Android projects, it's still likely that you'll reproduce some code 568across each project and this could become difficult to manage, especially when resolving 569bugs.</p></li> 570 <li><strong>Your application can adapt to device configuration changes.</strong> 571 <p>By creating a single APK that contains all the resources for each device configuration, your 572application can adapt to configuration changes that occur at runtime. For example, if the user docks 573or otherwise connects a handset device to a larger screen, there's a chance that this will invoke a 574system configuration change to support the larger screen. If you include all resources for different 575screen configurations in the same APK, then your application will load alternative resources and 576optimize the user experience for the new interface.</p> 577 </li> 578 <li><strong>App restore across devices just works.</strong> 579 <p>If a user has enabled data backup on his or her current device and then buys a new device 580that has a different configuration, then when the user's apps are automatically restored during 581setup, the user receives your application and it runs using the resources optimized for that device. 582For example, on a new tablet, the user receives your application and it runs with your 583tablet-optimized resources. This restore 584process does not work across different APKs, because each APK can potentially have different 585permissions that the user has not agreed to, so Google Play may not restore the application at 586all. (If you use multiple APKs, the user receives either the exact same APK if it's compatible or 587nothing at all and must manually download your application to get the APK designed for the new 588device.)</p></li> 589</ul> 590 591<p>The following sections describe some of the other options you should use to support multiple 592device configurations before deciding to publish multiple APKs.</p> 593 594 595 596<h3 id="TextureOptions">Supporting multiple GL textures</h3> 597 598<p>To support multiple types of GL textures with a single APK, your application should query the GL 599texture formats supported on the device and then use the appropriate resources or download 600them from a web server. For example, in order to keep the size of your APK small, you can query the 601device's support for different GL texture formats when the application starts for the first time and 602then download only the textures you need for that device.</p> 603 604<p>For maximum performance and compatibility, your application should use ETC1 textures wherever it 605doesn't impact the visual quality. However, because ETC1 cannot deal with images that have drastic 606chroma changes, such as line art and (most) text, and doesn't support alpha, it may not the best 607format for all textures.</p> 608 609<p>With a single APK, you should try to use ETC1 textures and uncompressed textures whenever 610reasonable, and consider the use of PVRTC, ATITC, or DXTC as a last resort when ETC1 does not 611suffice.</p> 612 613<p>Here's an example query for supported texture compression formats from inside a 614{@link android.opengl.GLSurfaceView.Renderer GLSurfaceView.Renderer}:</p> 615 616<pre> 617public void onSurfaceChanged(GL10 gl, int w, int h) { 618 String extensions = gl.glGetString(GL10.GL_EXTENSIONS); 619 Log.d("ExampleActivity", extensions); 620} 621</pre> 622 623<p>This returns a string that lists each of the supported compression formats.</p> 624 625 626 627<h3 id="ScreenOptions">Supporting multiple screens</h3> 628 629<p>Unless your APK file exceeds the Google Play size limit of 50MB, supporting multiple screens 630should always be done with a single APK. Since Android 1.6, the Android system manages most of the 631work required for your application to run successfully on a variety of screen sizes and 632densities.</p> 633 634<p>To further optimize your application for different screen sizes and densities, you should provide 635<a href="{@docRoot}guide/topics/resources/providing-resources.html#AlternativeResources">alternative 636resources</a> such as bitmap drawables at different resolutions and different layout designs for 637different screen sizes.</p> 638 639<p>For more information about how to support multiple screens with a single APK, read <a 640href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple Screens</a>.</p> 641 642<p>Additionally, you should consider using a support library from the <a 643href="{@docRoot}tools/support-library/index.html">Compatibility Package</a> so that you can add <a 644href="{@docRoot}guide/components/fragments.html">Fragments</a> to your activity designs 645when running on larger screens such as tablets.</p> 646 647 648 649<h3 id="ApiLevelOptions">Supporting multiple API levels</h3> 650 651<p>If you want to support as many versions of the Android platform as possible, you should use 652only APIs available in the lowest reasonable version. For example, your application may not require 653APIs newer than Android 2.1 (API Level 7), which makes an application available to 654over 95% of Android-powered devices (as indicated by the <a 655href="{@docRoot}about/dashboards/index.html">Platform Versions</a> dashboard).</p> 656 657<p>By using a support library from the <a 658href="{@docRoot}tools/support-library/index.html">Compatibility Package</a>, you can also use APIs 659from some of the latest versions (such as Android 3.0) while 660still supporting versions as low as Android 1.6. The support library includes APIs for <a 661href="{@docRoot}guide/components/fragments.html">Fragments</a>, <a 662href="{@docRoot}guide/components/loaders.html">Loaders</a>, and more. Using the fragment 663APIs is particularly valuable so that you can optimize your user interface for large devices such as 664tablets.</p> 665 666<p>Alternatively, if you want to use some APIs that are available only in newer versions of Android 667(which your application can still function without), then you should consider using reflection. By 668using reflection, you can check whether the current device supports certain APIs. If the APIs are 669not available, your application can gracefully disable and hide the feature.</p> 670 671<p>Another way to use new APIs only when running on a version that supports them is to check the 672API level of the current device. That is, you can query the value of {@link 673android.os.Build.VERSION#SDK_INT} and create different code paths depending on the API level 674supported by the device. For example:</p> 675 676<pre> 677if (android.os.Build.VERSION.SDK_INT >= 11) { 678 // Use APIs supported by API level 11 (Android 3.0) and up 679} else { 680 // Do something different to support older versions 681} 682</pre> 683 684 685<h3 id="CpuArchOptions">Supporting multiple CPU architectures</h3> 686 687<p>When using the Android NDK, you can create a single APK that supports multiple CPU architectures 688by declaring each of the desired architectures with the {@code APP_ABI} variable in the 689<code>Application.mk</code> file.</p> 690 691<p>For example, here's an <code>Application.mk</code> file that declares support for three 692different CPU architectures:</p> 693 694<pre> 695APP_ABI := armeabi armeabi-v7a mips 696APP_PLATFORM := android-9 697</pre> 698