將應用程式遷移至 Android 13
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本文以進階觀點提供一般開發和測試階段說明,協助您配合平台發布時程,擬定應用程式就緒度計畫,確保使用者享有出色的 Android 13 體驗。
每次發布 Android 版本時,我們都會推出新功能和行為變更,讓 Android 更實用、更安全且效能更佳。在多數情況下,您的應用程式均可立即正常運作,但在某些情況下,您可能需要更新應用程式以配合平台變更。
一旦原始碼發布到 Android 開放原始碼計畫 (Android 開放原始碼專案),使用者就能開始接收新平台,因此應用程式必須準備就緒,以便發揮使用者預期的效能,並展現新功能與 API 的最佳優勢,讓使用者能夠充分體驗新平台效益。
一般遷移作業分為兩個階段,可同時進行:
- 確保應用程式相容性 (在 Android 13 最終版本推出之前)
- 以新的平台功能和 API 為目標 (在最終版本發布後盡快實現)
確保與 Android 13 相容
請務必針對現有應用程式測試 Android 13 的功能,以確保使用者更新至最新 Android 版本時,能享有良好體驗。有些平台變更可能會影響應用程式的行為,因此請儘早進行全面的測試,並對應用程式進行必要的調整。
一般而言,你不需要變更應用程式的 targetSdkVersion
,即可調整應用程式並發布更新。同樣地,您應該也不需要使用新的 API 或變更應用程式的 compileSdkVersion
,但這取決於應用程式的建構方式和所使用的平台功能。
開始測試之前,請務必熟悉所有應用程式的行為變更。即使您未變更應用程式的 targetSdkVersion
,這些變更仍可能對您的應用程式造成影響。
將 Android 13 系統映像檔刷新至您的裝置,或下載 Android 模擬器的系統映像檔。
查看系統行為變更,找出應用程式可能受到影響的層面。
在裝置或模擬器上安裝應用程式,然後執行測試。留意系統行為變更,並逐步完成所有應用程式流程。
您只需要針對因應行為變更或解決問題,進行必要的程式碼變更。使用應用程式最初指定的 API 級別重新編譯,無需指定 Android 13 目標版本。
簽署、上傳及發布更新版 Android App Bundle 或 APK。
執行相容性測試
大部分情況下,Android 13 的測試相容性與一般應用程式測試類似。這是複習核心應用程式品質指南和測試最佳做法的絕佳時機。
如要進行測試,請在執行 Android 13 的裝置上安裝目前的已發布應用程式,並逐步完成所有流程與功能,同時確認是否有任何問題。為了協助您專注於測試,請參閱 Android 13 中導入的所有應用程式行為變更,瞭解可能影響應用程式功能或導致應用程式停止運作的行為變更。
此外,請務必檢查並測試受限制的非 SDK 介面使用情形。您應將應用程式使用的所有受限制介面更換為公開 SDK 或 NDK 的對應項目。請留意說明此類存取權限的 Logcat 警告,並使用 StrictMode
方法 detectNonSdkApiUsage()
,以程式設計方式進行擷取。
最後,請務必完整測試應用程式的程式庫和 SDK,以確保兩者可在 Android 13 上正常運作,並遵循隱私權、效能、使用者體驗和資料處理與權限的最佳做法。如有任何問題,請試著更新至最新版本的 SDK,或向 SDK 開發人員尋求協助。
完成測試並進行更新後,建議您立即發布相容的應用程式。如此可讓使用者及早測試應用程式,協助確保使用者在更新至 Android 13 之後,享有流暢的移轉體驗。
更新應用程式的指定目標,並使用新的 API 進行建構
發布相容的應用程式版本後,下一步就是更新 targetSdkVersion
,並善用 Android 13 中的新 API 和功能,提供 Android 13 的全方位支援。您準備就緒後即可進行更新,但請留意鎖定新平台目標版本的 Google Play 規定。
在您計畫全面支援 Android 13 的過程中,請檢閱影響指定 Android 13 為目標版本應用程式的行為變更。這些與鎖定目標版本相關的行為變更可能會導致需要您善加處理的功能問題。在某些情況下,這些變更需要大規模的開發,因此建議您盡早瞭解並解決這些問題。為方便找出會影響應用程式的特定行為變更,可以使用相容性切換按鈕來測試已啟用所選變更的應用程式。
下列步驟說明如何全面支援 Android 13。
安裝最新版本的 Android Studio 預先發布版,以便使用 Android 13 進行建構。請確認您有 Android 13 裝置或模擬器。
更新您的 targetSdkVersion
和其他建構設定。
查看會套用至指定 Android 13 為目標版本的應用程式行為變更。找出應用程式可能受影響的層面,並擬定支援方式。
編寫程式碼並進行必要的架構調整,以支援 Android 13 的使用者隱私變更。
善用 Android 13 API,為應用程式提供新功能與能力。針對 Android 13 重新編譯。
在 Android 13 裝置或模擬器上進行測試。將重點放在行為變更可能對應用程式造成影響的層面。試試看使用新 API 的功能。針對平台和 API 提供意見回饋。回報任何平台、API 或第三方 SDK 問題。
Android 13 API 定案後,請再次更新 targetSdkVersion
和其他建構設定、進行任何必要的更新,然後測試應用程式。
簽署、上傳及發布更新版 Android App Bundle 或 APK。
取得 SDK、變更指定目標、使用新的 API 進行建構
如要開始測試完整的 Android 13 支援功能,請使用最新的 Android Studio 預先發布版下載 Android 13 SDK 和其他所需工具。接著請更新應用程式的 targetSdkVersion
和 compileSdkVersion
,然後重新編譯應用程式。詳情請參閱 SDK 設定指南。
測試 Android 13 應用程式
編譯應用程式並將其安裝在執行 Android 13 的裝置上之後,請開始進行測試,以確保應用程式在以 Android 13 為目標的環境中能正常運作。某些行為變更僅會在應用程式鎖定新平台版本的情況下套用,因此請在測試前確認此類變更。
和進行基本的相容性測試一樣,逐步完成所有流程與功能測試,並確認是否有任何問題。將測試的重點放在指定 Android 13 版本作為目標版本的應用程式行為變更。建議您根據核心應用程式品質指南和測試最佳做法,對應用程式進行檢查。
請務必查看並測試可能適用的受限制非 SDK 介面的使用情形。請留意說明此類存取權限的 Logcat 警告,並使用 StrictMode 方法 detectNonSdkApiUsage()
,以程式設計方式進行擷取。
最後,請務必完整測試應用程式的程式庫和 SDK,以確保兩者可在 Android 13 上正常運作,並遵循隱私權、效能、使用者體驗和資料處理與權限的最佳做法。如有任何問題,請試著更新至最新版本的 SDK,或向 SDK 開發人員尋求協助。
使用「應用程式相容性」切換按鈕進行測試
Android 13 內含相容性切換按鈕,方便您對指定行為變更的應用程式進行測試。如果是可進行偵錯的應用程式,切換按鈕可讓您:
- 在不必實際變更應用程式 targetSdkVersion 的情況下,對鎖定的變更進行測試。您可以使用切換按鈕,強制啟用鎖定的特定行為變更,藉此評估該變更對現有應用程式的影響。
- 僅對特定變更進行測試。如果以指定版本為目標的變更中,您只想測試其中某些變更,則可使用切換按鈕停用不想測試的其他變更,不需要一次處理所有變更。
- 透過 ADB 管理切換按鈕。您可以在自動化測試環境中使用 ADB 指令啟用及停用可切換的變更。
- 使用標準變更 ID 加快偵錯速度。每個可切換的變更均有專屬的 ID 和名稱,可用於在記錄檔輸出中快速找出錯誤的起因。
當您準備變更應用程式的指定目標,或在進行支援 Android 13 的開發作業時,切換按鈕可提供實用協助。詳情請參閱「相容性架構變更 (Android 13)」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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 13.\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 13 final release)\n- Targeting the new platform features and APIs (as soon as possible after final release)\n\nEnsure compatibility with Android 13\n\nIt's important to test the functionality of your existing app against\nAndroid 13 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/13/behavior-changes-all). These changes might affect your app, even if you don't\nchange its `targetSdkVersion`. \nGet Android 13 \nFlash an Android 13 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 13. \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 13 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 13, 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/13/behavior-changes-all)** introduced in\nAndroid 13 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/13/changes/non-sdk-13)** . 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 13 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 13.\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 13 by updating its `targetSdkVersion`\nand taking advantage of new APIs and capabilities in Android 13.\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 13, review the\n[behavior changes that affect apps targeting Android 13](/about/versions/13/behavior-changes-13).\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/13/migration#using_app_compatibility_toggles) to test your app with selected changes enabled.\n\nThe following steps describe how to fully support Android 13. \nGet Android 13 SDK \nInstall the latest version of Android Studio preview to build\nwith Android 13. Make sure you have an Android 13 device or\nemulator. \n\nUpdate your `targetSdkVersion` and other build\nconfigurations. \nReview behavior changes \nReview the behavior changes that apply to apps targeting\nAndroid 13. 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 13's\nuser privacy changes. \nAdopt Android 13 features \nTake advantage of Android 13 APIs to bring new features and\ncapabilities to your apps. Recompile for Android 13. \nTest \nTest on an Android 13 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 13 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 13 support, use the latest\npreview version of Android Studio to download the Android 13 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/13/setup-sdk) for\ndetails.\n\nTest your Android 13 app\n\nOnce you've compiled the app and installed it on a device running\nAndroid 13, begin testing to ensure that the app works properly\nwhen targeting Android 13. Some behavior changes apply only when\nyour app is targeting the new platform, so you'll want to [review those\nchanges](/about/versions/13/behavior-changes-13) 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 13](/about/versions/13/behavior-changes-13)** . 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/13/changes/non-sdk-13)**\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 13 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 13 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 13 support, the toggles can help. For more information,\nsee [Compatibility framework changes (Android 13)](/about/versions/13/reference/compat-framework-changes)."]]