Android Studio:用于编码 UTF-8 的不可映射字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23677855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio : unmappable character for encoding UTF-8
提问by Chulo
After importing my project from eclipse into android studio i have got the following error :
将我的项目从 Eclipse 导入 android studio 后,出现以下错误:
Error: unmappable character for encoding UTF-8
Android Studio: 0.5.8
安卓工作室:0.5.8
回答by Mr. Blurred
I had the same problem because there was files with windows-1251 encoding and Cyrillic comments. In Android Studio which is based on IntelliJ IDEA you can solve it in two ways:
我遇到了同样的问题,因为有些文件带有 windows-1251 编码和西里尔文注释。在基于 IntelliJ IDEA 的 Android Studio 中,您可以通过两种方式解决它:
a)convert file encoding to UTF-8 or
a)将文件编码转换为 UTF-8 或
b)set the right file encoding in your build.gradlescript:
b)在build.gradle脚本中设置正确的文件编码:
android {
...
compileOptions.encoding = 'windows-1251' // write your encoding here
...
To convert file encoding use the menu at the bottom right corner of IDE. Select right file encoding first -> press Reload-> select UTF-8 -> press Convert.
要转换文件编码,请使用 IDE 右下角的菜单。首先选择正确的文件编码 -> 按Reload-> 选择 UTF-8 -> 按Convert。
Also read this Use the UTF-8, Luke! File Encodings in IntelliJ IDEA
回答by Priyanka Dadhich
Adding the following to build.gradle solves the problem :
将以下内容添加到 build.gradle 可以解决问题:
android {
...
compileOptions.encoding = 'ISO-8859-1'
}
回答by Samy Parjou
1/Convert the file encoding
File -> Settings -> Editor -> File encodings -> set UTF-8 for
1/转换文件编码
File -> Settings -> Editor -> File encodings -> set UTF-8 for
- IDE Encoding
- Project Encoding
- Default encoding propertie file
- IDE编码
- 项目编码
- 默认编码属性文件
Press OK
按确定
2/Rebuild Project
2/重建项目
Build -> Rebuild project
构建 -> 重建项目
回答by anil
I have the problem with encoding in javadoc generated by intellij idea. The solution is to add
我在intellij idea生成的javadoc中遇到编码问题。解决方法是添加
-encoding UTF-8 -docencoding utf-8 -charset utf-8
into command line arguments!
进入命令行参数!
UPDATE: more information about compilation Javadoc in Intellij IDEA see in my post
更新:有关 Intellij IDEA 中编译 Javadoc 的更多信息,请参阅我的帖子
回答by gc986
Add system variable (for Windows) "JAVA_TOOL_OPTIONS" = "-Dfile.encoding=UTF8".
添加系统变量(对于 Windows)“ JAVA_TOOL_OPTIONS”=“- Dfile.encoding=UTF8”。
I did it only way to fix this error.
我这样做是为了解决这个错误。
回答by ibrahnerd7
In Android Studio resolved it by
在 Android Studio 中通过
- Navigate to File> Editor> File Encodings.
- In global encoding set the encoding to
ISO-8859-1
- In Project encoding set the encoding to
UTF-8
and the same case to Default encoding for properties files. - Rebuild project.
- Navigate to File> Editor> File Encodings。
- 在全局编码中将编码设置为
ISO-8859-1
- 在项目编码中,将编码设置
UTF-8
为属性文件的默认编码,并将相同的情况设置为默认编码。 - 重建项目。
回答by Rahul
A few encoding issues that I had to face couldn't be solved by above solutions. I had to either update my Android Studio or run test cases using following command in the AS terminal.
上述解决方案无法解决我不得不面对的一些编码问题。我必须在 AS 终端中使用以下命令更新我的 Android Studio 或运行测试用例。
gradlew clean assembleDebug testDebug
gradlew clean assembleDebug testDebug
P.S your encoding settings for IDE and project should match.
PS 你的 IDE 和项目的编码设置应该匹配。
Hope it helps !
希望能帮助到你 !