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

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

问题描述

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

<块引用>

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

这是我没有进行任何更改或编写任何代码的情况.我阅读了有关 tools.android.com 的更多信息(
(来源: 评论,您需要进行 gradle 同步才能使其正常工作

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


(source: shrani.si)

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天全站免登陆