測試和偵錯
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
先決條件
開發人員預覽版不適用於正式版應用程式。因此必須使用 Google Play 服務 Beta 版。請參閱這份指南,瞭解如何註冊 Beta 版計畫。
如要執行及測試多裝置體驗,您必須擁有至少 2 個 Android 裝置
(例如手機和平板電腦)。裝置必須符合下列條件:
- 已安裝 Google Play 服務 Beta 版
- 使用相同的主要 Google 帳戶
- 已啟用「快速分享」,附近的裝置就能找到你的裝置
- 拉近彼此的距離
部署應用程式
透過 Android Studio 部署
透過 Android Studio 部署時,請完成下列步驟:
- 開啟應用程式的 Android Studio 專案。
- 依序前往「Run」>「Edit Configurations」。系統會隨即顯示「Run/Debug Configuration」視窗。
- 在「Launch Options」下方,將「Launch」設為應用程式主要或多裝置
活動。
- 依序點選「Apply」和「OK」。
- 按一下「Run」,在測試裝置上安裝應用程式。
使用指令列部署
使用指令列部署時,針對
以便測試多裝置體驗本節假設您擁有
應用程式模組為 crossdevice-app
。
./gradlew crossdevice-app:installDebug
# Start the app's activity. This example uses the sample app.
adb shell am start -n \
com.example.dtdi/com.example.crossdevice.MainActivity
偵錯提示
如要對應用程式進行偵錯,請按一下 Android Studio 中的「Debug」按鈕。
由於多裝置體驗具有非同步和分散式性質
可能難以只依賴偵錯善用
持續強化記錄與數據分析跨裝置 SDK 旨在提供回呼
因此無論是成功還是失敗的作業,您都需要處理這些
回呼和記錄輸出,方便偵錯。
如果轉移作業失敗,而且您無法啟動裝置探索功能或新的工作階段,可以嘗試開啟飛航模式再關閉,快速重設快速分享狀態。
提供意見
您的意見回饋對跨裝置 SDK 開發人員預覽版至關重要!如果您發現了任何問題,或希望針對 Android 上的跨裝置 SDK 提供改進意見,請告訴我們。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Testing and debugging\n\nPreconditions\n-------------\n\nThe Developer Preview isn't intended for use in production applications. Hence, it requires using a beta version of Google Play Services. See [this guide on how to enroll in the Beta Program](https://developers.google.com/android/guides/beta-program).\n\nTo run and test multidevice experiences, you must have at least two Android\ndevices (for example, a phone and a tablet). The devices must:\n\n- Have Google Play Services Beta installed\n- Use the same primary Google Account\n- Have [Quick Share enabled](https://support.google.com/android/answer/9286773) and be visible to nearby devices\n- Be in close proximity of each other\n\nDeploy your apps\n----------------\n\n### Deploy through Android Studio\n\nWhen deploying through Android Studio, complete the following steps:\n\n1. Open the Android Studio project for your app.\n2. Go to **Run \\\u003e Edit Configurations** . The **Run/Debug Configuration** window appears.\n3. Under **Launch Options** , set **Launch** to your app main or multidevice activity.\n4. Click **Apply** , and then **OK**.\n5. Click **Run** to install the app on your test device.\n\n### Deploy using the command line\n\nWhen deploying using the command line, repeat the steps for all devices used in\ntesting the multidevice experience. This section assumes that the name of your\napp module is `crossdevice-app`. \n\n ./gradlew crossdevice-app:installDebug\n # Start the app's activity. This example uses the sample app.\n adb shell am start -n \\\n com.example.dtdi/com.example.crossdevice.MainActivity\n\nTips for Debugging\n------------------\n\nTo debug the app, click the **Debug** button in Android Studio.\n\nGiven the asynchronous and distributed nature of multidevice experiences, it\nmight be difficult to rely only on debugging. Take advantage\nof logging and analytics. The Cross device SDK is designed to provide callbacks\nfor both successful and failed operations, so it's important to handle those\ncallbacks and log outputs for easier debugging.\n\nIf your transfer failed and you can't initiate device discovery or a new session, you can try turning Airplane Mode ON and OFF to quickly reset the quick share state.\n\nShare your feedback\n-------------------\n\nYour feedback is a crucial part of the Cross device SDK Developer Preview! Let us know of [any issues](https://issuetracker.google.com/issues/new?component=1205991&template=1706309) you find or ideas for improving the Cross device SDK on Android."]]