1、问题描述
最近在负责公司基础业务和移动基础设施的开发工作,正在负责Lint代码静态检查工作。因此编写了自定义的Lint规则,在调试过程中,编译的时候出现了如下所示的错误:
部分输出日志如下所示:
:XTCLintrRules:compileJava
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:16: 错误: 编码GBK的不可映射字符
* 瀹氫箟浠g爜妫?鏌ヨ鍒?
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:16: 错误: 编码GBK的不可映射字符
* 瀹氫箟浠g爜妫?鏌ヨ鍒?
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:17: 错误: 编码GBK的不可映射字符
* 杩欎釜鏄拡瀵归」鐩腑鐨勫浘鐗囧ぇ灏忕殑涓?涓垽鏂紝瓒呰繃250kb鐨勫叏閮ㄦ彁閱掑嚭鏉ワ紝璁╀粬浠帇缂?
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:17: 错误: 编码GBK的不可映射字符
* 杩欎釜鏄拡瀵归」鐩腑鐨勫浘鐗囧ぇ灏忕殑涓?涓垽鏂紝瓒呰繃250kb鐨勫叏閮ㄦ彁閱掑嚭鏉ワ紝璁╀粬浠帇缂?
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:32: 错误: 编码GBK的不可映射字符
private static final String ISSUE_DESCRIPTION = "閿欒锛氬浘鐗囨枃浠惰繃澶?";
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:33: 错误: 编码GBK的不可映射字符
private static final String ISSUE_EXPLANATION = "閿欒锛氬浘鐗囨枃浠惰繃澶э紝璇峰帇缂╀綘鐨勫浘鐗囨枃浠躲?傚浘鐗囧帇缂╂柟妗堝彲浠ュ弬鑰?: https://github.com/qjoy/TinyPNGNodeJSBatcher";
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:33: 错误: 编码GBK的不可映射字符
private static final String ISSUE_EXPLANATION = "閿欒锛氬浘鐗囨枃浠惰繃澶э紝璇峰帇缂╀綘鐨勫浘鐗囨枃浠躲?傚浘鐗囧帇缂╂柟妗堝彲浠ュ弬鑰?: https://github.com/qjoy/TinyPNGNodeJSBatcher";
^
D:\GitLab Source\XTCLint\XTCLintrRules\src\main\java\com\xtc\lint\rules\detectors\binaryResource\XTCImageFileSizeDetector.java:50: 错误: 编码GBK的不可映射字符
String reportStr = "閿欒锛氬浘鐗囨枃浠惰繃澶?: %d" + "KB,瓒呰繃浜嗛」鐩檺鍒剁殑:" + CHECK_IMAGE_KB_SIZE + "KB,璇疯繘琛屽浘鐗囧帇缂╂垨鎵綰I宸ョ▼甯堥噸鏂拌璁″嚭鍥?.";
主要原因是编译Java工程的时候,编译代码的编码方式有问题。
2、解决问题
如上图所示,在Java工程的build.gradle文件中,添加如下所示的代码:
//指定编译的编码
tasks.withType(JavaCompile){
options.encoding = "UTF-8"
}
添加如上所示的代码之后,重新编译即可正常,不会再弹出警告窗口。
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/77802596如果觉得本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创作!