Android Studio 1.2 - 默认情况下项目编码不匹配

2023-12-21

我是一个Android菜鸟,刚刚升级到Android Studio 1.2。当我创建一个新项目(API 16:Android 4.1(Jelly Bean))时,我立即收到以下警告:

警告:项目编码(windows-1252)与 Gradle 构建文件中指定的编码 (UTF-8)。这可能会导致 严重的错误。
更多的 信息...
打开文件编码 设置

我没有进行任何更改或编写任何代码。我在tools.android.com 上阅读了更多信息(http://tools.android.com/knownissues/encoding http://tools.android.com/knownissues/encoding)但它非常模糊,并且假设了解正在发生的事情(这就是“更多信息...”带您去的地方)。自从我更新到 Android Studio 1.2 以来,我的 XML 文件中的设计和文本选项卡甚至无法同步;设计选项卡无法编辑,而 XML 文件的文本文件可以编辑。我认为这是一个相关的问题。

为什么默认情况下它与此编码不匹配,我该怎么办以及我应该使用什么作为默认编码?

谢谢你!


Click File -> Settings (or click Ctrl + Alt + S) and find File Encodings in your Android Studio. See the image below as a reference.

现在你有三个选择

  • 更改项目编码以匹配 UTF-8,因为 Gradle 和 Android Lint 使用这个(推荐),
  • 或更改 IDE 编码以匹配其他编码,
  • 或者只是忽略该警告。如果到目前为止它对你有效,那么无论如何它都会继续有效

enter image description here
(source: shrani.si http://shrani.si/f/3V/p7/5xt1uxV/encoding.png)

Once you see the warning, you can directly click on "Open File Encoding Settings" as shown in the image below. This will take you to the same place as described above.

enter image description here

You can also see the current encoding of your file at the bottom right corner of Android studio. You can also change it there. See the image below.

IDE Encoding

您也可以在 build.gradle 脚本中指定字符集,如下所示

android {
    ...
    compileOptions {
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

根据Ashl7's https://stackoverflow.com/users/4522920/sorry-i-wont评论,你需要做一个 gradle 同步才能工作

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Studio 1.2 - 默认情况下项目编码不匹配 的相关文章

随机推荐