更新到 Java 8 后,Android 以错误的编码显示文本 [英] Android displays text in wrong encoding after update to Java 8

查看:22
本文介绍了更新到 Java 8 后,Android 以错误的编码显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的项目更新到 SDK 版本 24 和 Java 8,但遇到了一个奇怪的编码问题.

I've updated my project to SDK version 24 and Java 8 and encountered a strange encoding issue.

出于某种奇怪的原因,Android 将我的硬编码 UTF-8 字符串视为 Windows-1251,因此文本是乱码.

By some strange reason Android treats my hardcoded UTF-8 strings as Windows-1251 and thus the text is garbled.

像这样:

这是我改变的:

compileSdkVersion 24
buildToolsVersion "24.0.2"

compileOptions {
    encoding = 'utf-8'
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

我尝试过的:

  • 更改了 Android Studio 设置中的编码
  • 添加了 compileOptions.encoding = 'windows-1251' 和 compileOptions.encoding= 'utf-8'
  • 添加系统变量 JAVA_TOOL_OPTIONS:-Dfile.encoding=UTF8

如果我恢复到 Java 7 一切正常.

If I revert back to Java 7 everything is ok.

有什么想法吗?

推荐答案

这是 Jack 编译器的一个 bug,看看这个 发布.

This is a bug in Jack compiler, have a look at this post.

Jack 一直使用默认的 VM 编码,在 windows 上是 windows-1252.因此,您的文本使用 UTF-8 编码,并由 Jack 编译器使用 windows-1252 解码,这就是它们出现乱码的原因.

Jack has been using the default VM encoding, which on windows is windows-1252. So, your text is encoded with UTF-8 and decoded with windows-1252 by Jack compiler, and this is why they became garbled.

到目前为止,Gradle Plugin 不支持设置解码格式的 API,所以我们需要等待...

Until now, Gradle Plugin doesn't support an API to set the decode format, so we need to wait...

这篇关于更新到 Java 8 后,Android 以错误的编码显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆