将应用迁移到 Android 15
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文档对典型的开发和测试阶段进行了简要介绍,以帮助您制定与平台发布时间表保持一致的准备计划,并确保您的用户在 Android 15 上获得良好的体验。
每次发布新的 Android 版本时,我们都会推出一些全新的功能并引入一些行为变更,目的就在于提高 Android 的实用性、安全性和性能。在许多情况下,您的应用都可以直接使用并完全按预期运行;而在其他的一些情况下,您可能需要对应用进行更新以适应这些平台变更。
源代码发布到 AOSP(Android 开源项目)后,用户随之就可能开始使用新平台。因此,应用必须做好准备,让用户能够正常使用,最好还能利用新的功能和 API 发挥新平台的最大优势。
典型的迁移包含两个阶段,这两个阶段可以同时进行:
- 确保应用兼容性(在 Android 15 最终发布前)
- 针对新平台的功能和 API 调整应用(最终发布后尽快进行)
确保与 Android 15 兼容
您必须测试现有应用在 Android 15 上的运行情况,确保更新到最新版 Android 的用户获得良好的体验。有些平台变更可能会影响应用的行为方式,因此,必须尽早进行全面测试并对应用进行任何必要的调整。
您通常可以调整应用并发布更新,而无需更改应用的 targetSdkVersion
。同样,您应该也不需要使用新的 API 或更改应用的 compileSdkVersion
,不过这一点可能要取决于应用的构建方式及其所使用的平台功能。
在开始测试之前,请务必熟悉适用于所有应用的行为变更。即使您不更改应用的 targetSdkVersion
,这些变更也可能会影响您的应用。
将 Android 15 系统映像刷写到设备上,或下载适用于 Android 模拟器的系统映像。
查看系统行为变更,以确定变更可能会在哪些方面影响您的应用。
在设备或模拟器上安装您的应用,然后运行测试。重点关注系统行为变更,并完成所有应用流程。
只进行必要的代码更改,以适应行为变更或解决问题。使用应用最初面向的目标 API 级别重新编译,无需以 Android 15 为目标平台。
注册、上传并发布更新的 Android App Bundle 或 APK。
执行兼容性测试
在大多数情况下,测试与 Android 15 的兼容性与普通的应用测试类似。这时有必要回顾一下核心应用质量指南和测试最佳实践。
如要进行测试,请在搭载 Android 15 的设备上安装您当前发布的应用,并完成所有流程和功能,同时查找问题。为帮助您确定测试重点,请查看 Android 15 中引入的适用于所有应用的行为变更,这些变更会影响应用的功能或导致应用崩溃。
此外,请务必查看并测试受限非 SDK 接口的使用。您应使用应用公共 SDK 或 NDK 等效项替换应用使用的任何受限接口。留意突出显示这些访问权限的 logcat 警告,并使用 StrictMode
方法 detectNonSdkApiUsage()
以程序化地捕获它们。
最后,请务必完整测试应用中的库和 SDK,确保它们在 Android 15 上按预期运行,并遵循隐私权、性能、用户体验、数据处理和权限方面的最佳实践。如果您遇到问题,请尝试更新到最新版本的 SDK,或联系 SDK 开发者寻求帮助。
当您完成测试并进行更新后,我们建议您立即发布兼容的应用。这样可以尽早让您的用户测试应用,并帮助用户顺利过渡到 Android 15。
更新应用的目标平台并使用新 API 进行构建
发布应用的兼容版本后,下一步是通过更新 targetSdkVersion
并利用 Android 15 的新 API 和功能来添加对 Android 15 的全面支持。准备就绪后,您即可开始进行这些更新,请注意以新平台为目标平台的 Google Play 要求。
当您计划全面支持 Android 15 时,请查看影响以 Android 15 为目标平台的应用的行为变更。这些针对性的行为变更可能会导致需要解决的功能问题。在某些情况下,这些变更需要进行大量开发工作,因此我们建议您尽早了解并解决这些问题。为帮助确定影响您的应用的具体行为变更,请使用兼容性切换开关来测试已启用所选变更的应用。
以下步骤介绍了如何全面支持 Android 15。
安装最新版本的 Android Studio 预览版以使用 Android 15 进行构建。确保您拥有 Android 15 设备或模拟器。
更新您的 targetSdkVersion
和其他构建配置。
查看适用于以 Android 15 为目标平台的应用的行为变更。确定变更可能会在哪些方面影响您的应用,并规划如何提供支持。
进行所需的代码和架构更改,以支持 Android 15 的用户隐私权变更。
利用 Android 15 API,为您的应用引入新功能。针对 Android 15 重新编译。
在 Android 15 设备或模拟器上进行测试。重点关注行为变更可能会在哪些方面影响您的应用。试用使用新 API 的功能。提供平台和 API 反馈。报告任何平台、API 或第三方 SDK 问题。
在最终的 Android 15 API 发布后,再次更新 targetSdkVersion
和其他 build 配置,进行其他更新,并测试您的应用。
注册、上传并发布更新的 Android App Bundle 或 APK。
获取 SDK,更改目标平台,使用新 API 进行构建
如需开始针对 Android 15 全面支持进行测试,请使用最新预览版的 Android Studio 下载 Android 15 SDK,以及所需的任何其他工具。接下来,更新应用的 targetSdkVersion
和 compileSdkVersion
,然后重新编译应用。如需了解详情,请参阅 SDK 设置指南。
测试 Android 15 应用
编译应用并将其安装到搭载 Android 15 的设备上后,请开始测试,确保应用能够在 Android 15 上正常运行。某些行为变更仅在应用以新平台为目标平台时才适用,因此您需要在开始之前查看这些变更。
与基本兼容性测试一样,完成所有流程和功能以查找问题。将测试重点放在以 Android 15 为目标平台的应用的行为变更上。您还可以根据核心应用质量指南和测试最佳实践检查您的应用。
请务必查看并测试可能适用的受限非 SDK 接口的使用。留意突出显示这些访问权限的 logcat 警告,并使用 StrictMode 方法 detectNonSdkApiUsage()
以编程方式捕获它们。
最后,请务必完整测试应用中的库和 SDK,确保它们在 Android 15 上按预期运行,并遵循隐私权、性能、用户体验、数据处理和权限方面的最佳实践。如果您遇到问题,请尝试更新到最新版本的 SDK,或联系 SDK 开发者寻求帮助。
使用应用兼容性切换开关进行测试
Android 15 包含兼容性切换开关,可让您更轻松地在应用中测试针对性的行为变更。对于可调试的应用,切换开关可让您:
- 在不实际更改应用的 targetSdkVersion 的情况下测试针对性的变更。您可以使用切换开关强制启用特定的针对性行为变更,以评估对现有应用的影响。
- 仅针对特定变更进行测试。您可以使用切换开关停用除要测试的变更之外的所有针对性变更,而不必一次处理所有针对性变更。
- 通过 adb 管理切换开关。您可以使用 adb 命令在自动测试环境中启用和停用可切换的变更。
- 使用标准变更 ID 更快地进行调试。每个可切换的变更都具有唯一 ID 和名称,可用于在日志输出中快速调试根本原因。
在您准备更改应用的目标平台时,或者在您积极开发以便支持 Android 15 时,切换开关将十分有用。如需了解详情,请参阅兼容性框架变更 (Android 15)。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-27。"],[],[],null,["\u003cbr /\u003e\n\nThis document offers a high-level view of typical development and testing phases\nthat can help you make a plan for readiness that's well-aligned with the\nplatform release timeline and ensures a great experience for your users on\nAndroid 15.\n\nWith each release of Android, we introduce new features as well as behavior\nchanges aimed at making Android more helpful, more secure, and more performant.\nIn many cases your app will work exactly as expected out-of-the-box, while in\nother cases you might need to update your app to adapt to the platform changes.\n\nUsers can start receiving the new platform as soon as the source code is\nreleased to AOSP (Android Open Source Project), so it's important for your apps\nto be ready, performing as expected for users and ideally taking advantage of\nnew features and APIs to get the most out of the new platform.\n\nA typical migration has two phases, which can be concurrent:\n\n- Ensuring app compatibility (by Android 15 final release)\n- Targeting the new platform features and APIs (as soon as possible after final release)\n\nEnsure compatibility with Android 15\n\nIt's important to test the functionality of your existing app against\nAndroid 15 to ensure a great experience for users updating to the\nlatest version of Android. Some platform changes can affect the way your app\nbehaves, so it's important to test early and thoroughly and make any needed\nadjustments to your app.\n\nYou can usually adjust your app and publish an update without needing to change\nthe app's `targetSdkVersion`. Similarly, you shouldn't need to use new APIs or\nchange the app's `compileSdkVersion`, although this can depend on the way your\napp is built and the platform functionality it's using.\n\nBefore you start testing, be sure to familiarize yourself with the [behavior\nchanges for all apps](/about/versions/15/behavior-changes-all). These changes might affect your app, even if you don't\nchange its `targetSdkVersion`. \nGet Android 15 \nFlash an Android 15 system image to your device, or download\na system image for the Android emulator. \nReview changes \nReview system behavior changes to identify areas where your app\nmight be affected. \nTest \nInstall your app on your device or emulator, and run tests. Focus\non system behavior changes, and work through all app flows. \nUpdate \nMake only the code changes required to adapt to behavior\nchanges or resolve issues. Recompile with the same API level\nthat your app originally targeted - no need to target Android 15. \nPublish \nSign, upload, and publish your updated Android App Bundle\nor APK.\n\nPerform compatibility testing\n\nFor the most part, testing compatibility with Android 15 is\nsimilar to ordinary app testing. This is a good time to review the [core app\nquality guidelines](/docs/quality-guidelines/core-app-quality) and [best practices for testing](/training/testing).\n\nTo test, install your current published app on a device running\nAndroid 15, and work through all the flows and functionality\nwhile looking for issues. To help you focus your testing,\n**review the [behavior changes for all apps](/about/versions/15/behavior-changes-all)** introduced in\nAndroid 15 that can affect how your app functions or cause your\napp to crash.\n\nAlso make sure to **review and test for uses of [restricted non-SDK\ninterfaces](/about/versions/15/changes/non-sdk-15)** . You should replace any restricted interface your app uses with\na public SDK or NDK equivalent. Watch for logcat warnings that highlight these\naccesses, and use the `StrictMode` method [`detectNonSdkApiUsage()`](/reference/android/os/StrictMode.VmPolicy.Builder#detectNonSdkApiUsage()) to catch\nthem programmatically.\n\nLast, make sure to fully **test the libraries and SDKs in your app** to make\nsure they work as expected on Android 15 and follow best\npractices for privacy, performance, UX, data handling, and permissions. If you\nfind an issue, try updating to the latest version of the SDK, or reach out to\nthe SDK developer for help.\n\nWhen you've finished your testing and made any updates, we recommend publishing\nyour compatible app right away. This lets your users test the app early and\nhelps ensure a smooth transition for your users as they update to\nAndroid 15.\n\nUpdate the app's targeting and build with new APIs\n\nOnce you've published a compatible version of your app, the next step is to add\nfull support for Android 15 by updating its `targetSdkVersion`\nand taking advantage of new APIs and capabilities in Android 15.\nYou can make these updates as soon as you're ready, keeping in mind the [Google\nPlay requirements](/distribute/play-policies) for targeting the new platform.\n\nAs you plan your work to fully support Android 15, review the\n[behavior changes that affect apps targeting Android 15](/about/versions/15/behavior-changes-15).\nThese *targeted behavior changes* might cause functional issues you then need to\naddress. In some cases, these changes require significant development, so we\nrecommend learning about and addressing them as early as possible. To help\nidentify specific behavior changes that affect your app, use the [compatibility\ntoggles](/about/versions/15/migration#using_app_compatibility_toggles) to test your app with selected changes enabled.\n\nThe following steps describe how to fully support Android 15. \nGet Android 15 SDK \nInstall the latest version of Android Studio preview to build\nwith Android 15. Make sure you have an Android 15 device or\nemulator. \n\nUpdate your `targetSdkVersion` and other build\nconfigurations. \nReview behavior changes \nReview the behavior changes that apply to apps targeting\nAndroid 15. Identify areas where your app might be affected,\nand plan how to support them. \nCheck against new privacy changes \nMake code and architecture changes needed to support Android 15's\nuser privacy changes. \nAdopt Android 15 features \nTake advantage of Android 15 APIs to bring new features and\ncapabilities to your apps. Recompile for Android 15. \nTest \nTest on an Android 15 device or emulator. Focus on areas\nwhere behavior changes might affect your app. Try out\nfunctionality that uses new APIs. Provide platform and API\nfeedback. Report any platform, API, or third-party SDK issues. \nFinal update \nOnce Android 15 APIs are final, update your\n`targetSdkVersion` and other build configurations\nagain, make any additional updates, and test your app. \nPublish \nSign, upload, and publish your updated Android App Bundle\nor APK.\n\nGet the SDK, change targeting, build with new APIs\n\nTo start testing for full Android 15 support, use the latest\npreview version of Android Studio to download the Android 15 SDK\nand any other tools you need. Next, update your app's `targetSdkVersion` and\n`compileSdkVersion`, and re-compile the app. See the [SDK setup guide](/about/versions/15/setup-sdk) for\ndetails.\n\nTest your Android 15 app\n\nOnce you've compiled the app and installed it on a device running\nAndroid 15, begin testing to ensure that the app works properly\nwhen targeting Android 15. Some behavior changes apply only when\nyour app is targeting the new platform, so you'll want to [review those\nchanges](/about/versions/15/behavior-changes-15) before getting started.\n\nAs with basic compatibility testing, work through all the flows and\nfunctionality looking for issues. Focus your testing on the\n**[behavior changes for apps targeting Android 15](/about/versions/15/behavior-changes-15)** . It's\nalso a good time to check your app against the [core app quality guidelines](/docs/quality-guidelines/core-app-quality)\nand [best practices for testing](/training/testing).\n\nMake sure to review and **test for uses of [restricted non-SDK interfaces](/about/versions/15/changes/non-sdk-15)**\nthat may apply. Watch for logcat warnings that highlight these accesses and use\nthe StrictMode method [`detectNonSdkApiUsage()`](/reference/android/os/StrictMode.VmPolicy.Builder#detectNonSdkApiUsage()) to catch them\nprogrammatically.\n\nLast, make sure to fully **test the libraries and SDKs in your app** to make\nsure they work as expected on Android 15 and follow best\npractices for privacy, performance, UX, data handling, and permissions. If you\nfind an issue, try updating to the latest version of the SDK, or reach out to\nthe SDK developer for help.\n\nTest using app compatibility toggles\n\nAndroid 15 includes compatibility toggles that make it easier to test your app\nwith targeted behavior changes. For a debuggable app, the toggles let you:\n\n- **Test targeted changes without actually changing the app's\n targetSdkVersion**. You can use the toggles to force-enable specific targeted behavior changes to evaluate the impact on your existing app.\n- **Focus your testing on specific changes only**. Rather than having to address all targeted changes at once, the toggles let you disable all targeted changes except the ones you want to test against.\n- **Manage toggles through adb**. You can use adb commands to enable and disable the toggleable changes in your automated test environment.\n- **Debug faster using standard change IDs**. Toggleable changes each have a unique ID and name that you can use to quickly debug root cause in log output.\n\nAs you prepare for changing your app's targeting, or while you in active\ndevelopment for Android 15 support, the toggles can help. For more information,\nsee [Compatibility framework changes (Android 15)](/about/versions/15/reference/compat-framework-changes)."]]