调试表盘
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了如何调试使用表盘格式构建的表盘。还介绍了如何验证表盘 XML 并识别运行时错误。
检查是否有有效的表盘格式文档
由于表盘格式要求使用符合已发布 XSD 的结构良好的 XML,因此您可以确认表盘是否有效,并找出错误。
使用 XML 验证工具找出构建过程中的问题。此工具已集成到示例表盘的构建流程中。
如果您要构建用于创建表盘的工具,请确保该工具在执行 XML 验证时使用 XSD。
手动运行验证工具的示例:
java -jar wff-validator.jar 2 ~/MyWatchface/res/raw/watchface.xml
如果 watchface.xml
文档中存在错误,您会看到错误消息,例如在本例中,height
被错拼为 hight
:
INFO: DWF Validation Application Version 1.0. Maximum Supported Format Version #2
SEVERE: [Line 41:Column 53]: cvc-complex-type.3.2.2: Attribute 'hight' is not allowed to appear in element 'PartDraw'.
INFO: ❌ FAILED : watchface.xml is NOT valid against watch face format version #1
验证程序会指明需要更正的元素的位置(第 41 行、第 53 列)。
了解如何获取 XML 验证器工具并构建该工具以供使用。
找出运行时错误
仅确保 XML 本身有效并不足以发现所有潜在问题。
例如,您的 XML 可能引用不存在的字体或可绘制资源,或者表达式本应生成数字值,但却生成字符串。
对于此类问题,在 Android Studio 中或通过 ADB 使用 Logcat 是获取更多详细信息的好方法。
按“运行时”过滤,您将能够看到影响表盘的严重问题和非严重问题。例如,在这里,为不存在的 HourHand
指定资源时:
E Invalid resource ID 0x00000000.
E FATAL EXCEPTION: main
Process: com.google.wear.watchface.runtime, PID: 29115 android.content.res.Resources$NotFoundException: Resource ID #0x0
或者,在尝试使用拼写有误的颜色主题时,会出现以下情况:
W color has wrong type of source:CONFIGURATION.myTheeeme.2[OBJECT:]
E Cannot parse theme color. Using theme color WHITE
本页面上的内容和代码示例受内容许可部分所述许可的限制。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,["# Debug a watch face\n\nThis page describes how to debug a watch face built with the Watch Face Format.\nIt also explains how to validate your watch face XML and identify runtime\nerrors.\n\nCheck for valid Watch Face Format documents\n-------------------------------------------\n\nAs the Watch Face Format requires well-structured XML that conforms to a\npublished XSD, you can confirm whether your watch face is valid or not,\nand identify errors.\n\nUse the [XML validation tool](https://github.com/google/watchface/tree/main/third_party/wff) to identify issues during the build\nprocess. This tool is integrated into the build process in the [sample watch\nfaces](https://github.com/android/wear-os-samples/tree/main/WatchFaceFormat).\n\nIf you are building a tool for creating watch faces, be sure that the tool\nperforms XML validation [using the XSD](https://github.com/google/watchface/tree/main/third_party/wff/specification/documents) in your tool.\n\nAn example of running the validation tool manually: \n\n java -jar wff-validator.jar 2 ~/MyWatchface/res/raw/watchface.xml\n\nIf there is an error in your `watchface.xml` document, you'll see an error, such\nas in this case where `height` has been misspelled as `hight`: \n\n INFO: DWF Validation Application Version 1.0. Maximum Supported Format Version #2\n SEVERE: [Line 41:Column 53]: cvc-complex-type.3.2.2: Attribute 'hight' is not allowed to appear in element 'PartDraw'.\n INFO: ❌ FAILED : watchface.xml is NOT valid against watch face format version #1\n\nThe validator identifies the location---line 41, column 53---of the element that\nneeds to be corrected.\n\nLearn how to [obtain the XML validator tool](https://github.com/google/watchface/blob/main/third_party/wff/README.md) and build it for\nuse.\n\n### Identify runtime errors\n\nEnsuring the XML itself is valid is not enough to capture all potential issues.\n\nFor example, your XML might reference a font or drawable resource that does not\nexist, or an expression might be expected to produce a numeric value, but\ninstead results in a string.\n\nFor these types of issues, using logcat, either in Android Studio or through ADB\nis a good way to get more detailed information.\n\nFilter on \"runtime\" and you'll be able to see both fatal and nonfatal issues\naffecting the watch face. For example, here, when specifying a resource for\n`HourHand` which does not exist: \n\n E Invalid resource ID 0x00000000.\n E FATAL EXCEPTION: main\n Process: com.google.wear.watchface.runtime, PID: 29115 android.content.res.Resources$NotFoundException: Resource ID #0x0\n\nOr here, when trying to use a color theme with a typo in it: \n\n W color has wrong type of source:CONFIGURATION.myTheeeme.2[OBJECT:]\n E Cannot parse theme color. Using theme color WHITE"]]