测试和调试
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
前提条件
开发者预览版不适合在正式版应用中使用。因此,它需要使用 Beta 版 Google Play 服务。请参阅这份指南,了解如何注册加入 Beta 版计划。
如需运行和测试多设备体验,您必须拥有至少两个 Android 设备
设备(例如手机和平板电脑)。设备必须:
- 已安装 Google Play 服务 Beta 版
- 使用相同的主要 Google 账号
- 已启用“快速分享”功能,且让附近的设备可以看到
- 彼此靠近
部署应用
通过 Android Studio 部署
通过 Android Studio 进行部署时,请完成以下步骤:
- 打开应用的 Android Studio 项目。
- 依次进入 Run > Edit Configurations。此时将显示 Run/Debug Configuration 窗口。
- 在 Launch Options 下,将 Launch 设为应用的主设备或多设备模式
活动。
- 点击 Apply,然后点击 OK。
- 点击 Run 以在测试设备上安装应用。
使用命令行进行部署
使用命令行进行部署时,请针对
测试多设备体验本部分假定您的
app 模块是 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 按钮。
鉴于多设备体验的异步和分布式特性,
可能很难仅依靠调试来实现。利用
日志和分析的Cross Device SDK 旨在提供回调
因此,请务必妥善处理
回调和记录输出,以简化调试。
如果传输失败,并且无法启动设备发现或新会话,您可以尝试开启和关闭飞行模式,以快速重置快速分享状态。
分享反馈
您的反馈对跨设备 SDK 开发者预览版至关重要!如果发现任何问题,或有任何关于改进 Android 版跨设备 SDK 的想法,欢迎告诉我们。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-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-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."]]