Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

Android Studio 1.2 - Project encoding mismatches by default

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here
(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.

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...