適用於 Android 的 .NET 錯誤 XA1047

範例訊息

error XA1047: Required attribute 'from' missing from element 'replace-type'; /path/to/jni-remapping.xml line 3.
error XA1047: Required attribute 'source-type' missing from element 'replace-method'; /path/to/jni-remapping.xml line 7.

Issue

JNI 重映射 XML 檔案中的某元素缺少一個必需屬性。 <replace-type>和 <replace-method> 元素各自擁有必須具備的屬性。

<replace-type> 的必要屬性:

  • from— 原始 Java 型別名稱(例如 com/example/OldClass)
  • to— 替代的 Java 型別名稱(例如 com/example/NewClass)

<replace-method> 的必要屬性:

  • source-type— 包含原始方法的 Java 型別
  • source-method-name — 原始方法的名稱
  • target-type— 包含替換方法的 Java 型別
  • target-method-name — 替換方法的名稱
  • target-method-instance-to-static — 替換是否將實例方法轉換為靜態方法(true 或 false)

解決方案

將遺漏的必要屬性新增至 JNI 重映射 XML 檔案中的元素。 例如:

<replacements>
  <replace-type from="com/example/OldClass" to="com/example/NewClass" />
  <replace-method
    source-type="com/example/Source"
    source-method-name="instanceMethod"
    target-type="com/example/Target"
    target-method-name="staticMethod"
    target-method-instance-to-static="true" />
</replacements>