對錶面進行偵錯
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何偵錯使用錶面格式建構的錶面。並說明如何驗證錶面 XML 和識別執行階段錯誤。
檢查是否有有效的錶面格式文件
錶面格式需要符合已發布 XSD 的結構完整 XML,因此您可以確認錶面是否有效,並找出錯誤。
使用 XML 驗證工具,找出建構過程中的問題。這個工具已整合至範例錶面的建構程序。
如果您要建構用於建立錶面的工具,請務必確保該工具會在工具中使用 XSD 執行 XML 驗證。
手動執行驗證工具的範例:
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 可能會參照不存在的字型或可繪製資源,或是預期運算式會產生數值,但實際上卻產生字串。
針對這類問題,使用 logcat (在 Android Studio 中或透過 ADB) 是取得詳細資訊的好方法。
篩選「執行階段」,即可查看影響錶面的嚴重和一般問題。例如,如果您為不存在的 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 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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"]]