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