Android Studio 1.2 - 默认情况下,项目编码不匹配 [英] Android Studio 1.2 - Project encoding mismatches by default

查看:219
本文介绍了Android Studio 1.2 - 默认情况下,项目编码不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


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


这没有我已作出任何修改或书面任何代码。我阅读了关于tools.android.com的更多信息(评论你需要做一个毕业生同步工作才能工作


I'm a bit of an Android rookie, and I just upgraded to Android Studio 1.2. When I make a new project (API 16: Android 4.1 (Jelly Bean)), I immediately get the following warning:

Warning:The project encoding (windows-1252) does not match the encoding specified in the Gradle build files (UTF-8). This can lead to serious bugs.
More Info...
Open File Encoding Settings

This is without me having made any changes or written any code whatsoever. I read up on more info on tools.android.com (http://tools.android.com/knownissues/encoding) but it is incredibly vague and assumes knowledge on what's going on (this is where "More info..." takes you). Since I updated to Android Studio 1.2, the design and text tabs in my XML-files won't even sync up; the design tab cannot be edited while the textfile of XML-files can be. I assume that's a related issue.

Why does it mismatch this encoding by default, what can I do about it and what should I use as default encoding?

Thank you!

解决方案

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

Now you have three options

  • Change project encoding to match UTF-8 since both Gradle and Android Lint use this (recommended),
  • or change IDE encoding to match other encoding,
  • or just simply ignore the warning. If it worked out for you so far, it will continue to work anyway

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.

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.

Also you can specify charset in your build.gradle script like this

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

According to Ashl7's comment, you need to do a gradle sync for this to work

这篇关于Android Studio 1.2 - 默认情况下,项目编码不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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