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