Android 数据绑定生成非 UTF-8 编码的文件

Android databinding generates files that are not UTF-8 encoded

我正在使用数据绑定实用程序。每当我在 xml 文件中使用“_i”时,它在绑定 class 中对应的字符是“\ufffd”,它是 windows 中的大写 i(“İ”)- 1254编码。这是土耳其字母表中正确的大写字母,但我不想使用本地大写字母,因为它会产生以下错误:

error: illegal character: '\ufffd'

查看了非法字符错误相关的问题,大部分建议删除非法字符重写。但是在我的情况下,我无法更改文件,或者更改没有意义,因为它是在重建期间重新生成的。

row_program_item.xml

<LinearLayout
    android:id="@+id/program_item_linear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    ...
</LinearLayout>

RowProgramItemBinding.java

...
@NonNull
public final LinearLayout program�temLinear;

我建议在编写视图 ID 时使用驼峰式大小写。
如果您查看其中一个答案 here.

If you take to look at android.R.id.* fields, you will notice that all of them are in camel-case. So if the android ids are written in camel-case, I guess we have to follow this convention :)

这样您就可以轻松避免该错误。

P.S。我也使用驼峰命名我的变量 对于 /Res 文件夹下的文件,我使用 snake_case 除此之外,我已经使用 camelCase

希望对您有所帮助

正如@Joachim Sauer 所说,这是一个错误。目前,解决方案是更改 javac 的语言以避免本地化。就我而言,它有助于将以下行添加到 gradle.properties.

org.gradle.jvmargs=-Duser.country=TR -Duser.language=en
kotlin.compiler.execution.strategy=in-process
kotlin.daemon.jvm.options=-Duser.country=TR -Duser.language=en